oauth2-bundle icon indicating copy to clipboard operation
oauth2-bundle copied to clipboard

unsupported_grant_type

Open zhukovsergei opened this issue 5 years ago • 6 comments
trafficstars

Hi colleagues, Actually I couldn't find any information about correct URL for oauth server. I just expected to receive the "code" or something for getting a token. Can you say what I'm doing wrong?

image

zhukovsergei avatar Oct 14 '20 15:10 zhukovsergei

The routes for the endpoints are defined here: https://github.com/trikoder/oauth2-bundle/blob/v3.x/Resources/config/routes.xml

I'm not sure what are you trying to do - a client credentials grant request or an authorization code grant request?

Client credentials test example: https://github.com/trikoder/oauth2-bundle/blob/v3.x/Tests/Acceptance/TokenEndpointTest.php#L37

Auth code grant test example: https://github.com/trikoder/oauth2-bundle/blob/v3.x/Tests/Acceptance/AuthorizationEndpointTest.php#L47 and then https://github.com/trikoder/oauth2-bundle/blob/v3.x/Tests/Acceptance/TokenEndpointTest.php#L137

X-Coder264 avatar Oct 14 '20 15:10 X-Coder264

I'm not sure what are you trying to do - a client credentials grant request or an authorization code grant request?

I just want to authenticate a user (like we are doing via FB or Google). So if I right understand i need first send a GET request with some parameters: request_uri, scope, app id and secret like here:

image Then I expect to receive the code. Thanks for the links. I will check it!

zhukovsergei avatar Oct 14 '20 15:10 zhukovsergei

@X-Coder264 Am I right understand, that with this request I should receive a code from a server?

image

zhukovsergei avatar Oct 14 '20 15:10 zhukovsergei

You can find the auth code grant documentation here: https://github.com/trikoder/oauth2-bundle/pull/177/files

The endpoint URL depends on how you've imported the routes.xml from the bundle in your project (with or without some prefix for example).

You can find further documentation about that grant type on the web, for example: https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-type

X-Coder264 avatar Oct 14 '20 16:10 X-Coder264

@X-Coder264 Well, almost get it, but have an error: HTTP/1.1 401 Unauthorized returned for "http://127.0.0.1:8001/token".

image

image

So, I resolved this with change in http request: 'grant_type' => 'authorization_code', on 'grant_type' => 'client_credentials', And it works. I have the token. Have no idea why, because on tests is 'grant_type' => 'authorization_code', Even if in database table:oauth2_client I change grant_type to authorization_code it still doesn't work. Only client_credentials

zhukovsergei avatar Oct 16 '20 08:10 zhukovsergei

Can I ask you @X-Coder264 Where to set a user fields for access_token and why I have scope there 'read' when I have 'user.view'.

image

When I set $event->setUser() in AuthorizationCodeListener it works only for authorization_code table. But where for access_token?

zhukovsergei avatar Oct 16 '20 15:10 zhukovsergei