-
Notifications
You must be signed in to change notification settings - Fork 90
Unexplained Client authentication failed error #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same here. How this code:
gets the user? I can't found a listener for: OAuth2Events::USER_RESOLVE |
@Kerrialn I have solved it like this in my project but I am surprised that there is not documented. App\EventListener\UserResolveListener.php
In my services.yaml:
|
The password grant was documented in the previous repository -> https://github.com/trikoder/oauth2-bundle/blob/v3.x/docs/password-grant-handling.md Then it was removed from this bundle as the OAuth spec deprecated it (you should use auth code grant with PKCE instead). After the removal it was brought back to ease the migration path from the Trikoder bundle (and I guess the documentation for it was forgotten to be returned in that step). https://oauth2.thephpleague.com/authorization-server/which-grant/
The Password Grant and Implicit Grant are not included in our recommendation diagram as these grants have several drawbacks and/or are no longer considered to be best practice. Password Grant We strongly recommend that you use the Authorization Code flow over the Password grant for several reasons. The Authorization Code Grant redirects to the authorization server. This provides the authorization server with the opportunity to prompt the user for multi-factor authentication options, take advantage of single-sign-on sessions, or use third-party identity providers. The Password grant does not provide any built-in mechanism for these and must be extended with custom code. |
@X-Coder264 Thank you for the response. So the password grant is no long advised, however the documentation example of the Authorization Code Grant is very limited, especially when it comes to Symfony integration. Do you know of any up-to-date guide for this? |
@Kerrialn We have an old WIP PR for that on the old repository -> trikoder/oauth2-bundle#177 It's on my TODO list to send a PR here for it (and some other documentation improvements) soon. If you or somebody else has the time to do it sooner, please do. |
@X-Coder264 or anyone else who can answer. I'm happy to do it, but even with the PR you sent, the process isn't very clear. What I did so far:
basically I need to know how to implement a simple password auth using the Authorization Code flow? If you have a simple code example of a working Symfony app with the Authorization Code flow integrated, that'd be very useful and I'll create a PR for the documentation. |
@Kerrialn The authorization code grant flow has two requests. The first request is a GET request to the authorization endpoint (example in the tests is here -> https://github.com/thephpleague/oauth2-server-bundle/blob/v0.2.0/tests/Acceptance/AuthorizationEndpointTest.php#L66). On this request your For third party clients there's usually an additional step (the approve/deny request page) to which the user gets redirected after they login (this logic is again handled by that listener which gets triggered on the authorization request) -> an example of such a listener can be found here -> https://gist.github.com/ajgarlag/1f84d29ee0e1a92c8878f44a902338cd. The second request is a POST request to the token endpoint to get the access token (here you send the previously parsed authorization code from the Also for PKCE you need to create a public client (it means the client has no secret on it, hence you don't send it in any request). |
@X-Coder264 Thanks for the detailed response, I now understand the flow. What isn't clear is how it's integrated into Symfony, what is handled by the package and what needs to be manually coded. I've created an example project . feel free to point out what's missing or incorrect.
Authorization Code Grant with PKCE:
|
@Kerrialn In the auth code grant your backend app is the authorization server which means it must have a login mechanism (and the usual one is a simple session login form, or Google/Facebook/whatever login, or both). It doesn't matter if your client application is a web or mobile app that uses APIs, those are unrelated things. The else {
$response = new JsonResponse('authentication failed', 200);
$event->setResponse($response);
} This should be changed to return a 302 redirect response to your login route which would display the login form. The redirect response should have a The login flow is standard Symfony stuff (https://symfony.com/doc/current/security.html#form-login) so it's not separately documented here. The idea is that you either use The two requests described in my previous post can be sent via Postman. The first one can be sent via the browser feature of Postman (AFAIK) so that Postman opens your login form, you fill it and submit it and get a redirect response back after which you can manually copy/paste the given auth code from the query into the second request to get the access token.
Just to clarify, having Google or Facebook login ability on your authorization server does not have anything to do with whether the client is third party or not. A third party client would be when Google would give their users a "login with FooApplication" button (where TLDR; This package handles the auth code grant flow and the only thing it needs from a developer is the authorization listener in order to work. This package only expects that the listener does what it's expected to do (approve valid authorization requests). It does not care how you implement the login functionality in order to be able to approve those requests. |
Stack:
installed the package and added to bundle config.
config/routes.yaml
openssl genrsa -out ./var/oauth/private.key
openssl rsa -in ./var/oauth/private.key -pubout -out ./var/oauth/public.key
bin/console league:oauth2-server:create-client FrontEnd --grant-type=password --grant-type=refresh_token
/config/league_oauth2_server.php
/config/packages/security.php
Post request to
/token
Data in body:
Response:
client in the database all other oauth2 tables are empty:

The text was updated successfully, but these errors were encountered: