XF 2.3 Using XF 2.3 OAuth Provider

Kirby

Well-known member
Nope, already tried but it returns a lot of empty fields but none shows who logs in right after I'm successfully authenticated.
Haven't retested on beta 3 though.
Works just fine for me using League OAuth2 Client with 2.3.0 Beta 1 (I'd expect it also works with Beta 2 & 3).

PHP:
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => '...',    // The client ID assigned to you by the provider
    'clientSecret'            => '...',    // The client password assigned to you by the provider
    'redirectUri'             => 'http://dev.local/oauth/test.php',
    'urlAuthorize'            => 'http://dev.local/xf23/index.php?oauth2/authorize',
    'urlAccessToken'          => 'http://dev.local/xf23/index.php?api/oauth2/token',
    'urlResourceOwnerDetails' => 'http://dev.local/xf23/index.php?api/me'
]);

Code:
Access Token: 2SHthq5lpp6qa8lRRFNq3VAhcVhlZmM1
Refresh Token: U5-HZPEHBiBmm4oBvH2L6WOn0YuwZvio
Expired in: 1712708864
Already expired? not expired
array ( 'me' => array ( 'avatar_urls' => array ( 'o' => NULL, 'h' => NULL, 'l' => NULL, 'm' => NULL, 's' => NULL, ), 'can_ban' => false, 'can_converse' => true, 'can_edit' => true, 'can_follow' => false, 'can_ignore' => false, 'can_post_profile' => true, 'can_view_profile' => true, 'can_view_profile_posts' => true, 'can_warn' => false, 'is_banned' => false, 'is_followed' => false, 'is_ignored' => false, 'is_staff' => true, 'last_activity' => 1712701661, 'location' => '', 'message_count' => 3, 'profile_banner_urls' => array ( 'l' => NULL, 'm' => NULL, ), 'question_solution_count' => 0, 'reaction_score' => 0, 'register_date' => 1710884408, 'signature' => '', 'trophy_points' => 1, 'user_id' => 1, 'user_title' => 'Administrator', 'username' => 'Kirby', 'view_url' => 'http://dev.local/xf23/index.php?members/kirby.1/', 'vote_score' => 0, 'warning_points' => 0, ), )
 
Last edited:
I thought when you call the endpoint with /api/* , you are required to give the API key along with?
Not if OAuth2 is used; the access token acts as the "API Key" in this case.

In my case, it simply does not work but I see it does work for you. I'm writing my own oauth2 client in different language other than php though.
I don’t know your code, but you are most likely doing smth. wrong as the used language doesn't matter.

Just include the access token via request header Authorization: Bearer <token> as usual and it should work.
 
Not if OAuth2 is used; the access token acts as the "API Key" in this case.


I don’t know your code, but you are most likely doing smth. wrong as the used language doesn't matter.

Just include the access token via request header Authorization: Bearer <token> as usual and it should work.
Can't make it work with Postman. I will need to debug more and add custom code to see and probably upgrade external libraries to newer versions. Thanks.
 
I traced the code, right after I call the endpoint , I got a http 400.
1712789955964.webp
This is my config on postman locally

1712790159142.webp

On postman, it always says I need api key

Still don't know what I did wrong, Postman says I'm authenticated and copy paste the token

1712790221674.webp
1712790039263.webp

1712790290549.webp
 
Did you check your webserver config?

The Authorization header might not be passed to PHP.

If you use Apache you could try to add SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 to .htaccess
 
I nailed it down , it's working now with postman, I have to uncomment this line in .htaccess

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

1712791548982.webp
 
I have a similar issue.
I have the RewriteRule in .htaccess
but still get a the no_api_key_in request_error discussed here:

{"errors":[{"code":"no_api_key_in_request","message":"No API key was included in the request.","params":[]}]}
 
Last edited:
I'm trying to use Postman with our forum running CentOs (CentMinMod) with Nginx. I've setup a superuser API key with access to all nodes, and setup the XF-Api-Key value in the Postman collection. I have the following data returned regardless of the node requested:

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

dropping /api/users/ from the request, I get a 200 OK return code from the webserver.

I have been following the setup from this thread: https://xenforo.com/community/resources/how-to-call-the-xenforo-api.7875/.

Update:
I had misspelled the key name for the header API. Everything seems to be working as expected at this point.
 
Last edited:
Back
Top Bottom