mezzio-authentication-oauth2
mezzio-authentication-oauth2 copied to clipboard
Body Parsing Middleware Requirement
Hi, I has having an issue with getting this oauth2 library up and running where I would constantly get 'Unsupported Grant Type' while making Json requests for an access token. The Content-Type was set to application/json in the header.
Example:
Request:
{ "grant_type": "authorization_code", "client_id" : "test_client", "client_secret" : "test_secret", "redirect_uri " : "localhost", "code" : "545604564056" }
Response:
{ "error": "unsupported_grant_type", "error_description": "The authorization grant type is not supported by the authorization server.", "hint": "Check that all required parameters have been provided", "message": "The authorization grant type is not supported by the authorization server." }
The same error would occur regardless of what grant_type was set to.
The cause of the error was due to how https://oauth2.thephpleague.com/ parses the body of the request.
The League\OAuth2\Server\Grant\AbstractGrant class has methods such as canRespondToAccessTokenRequest and getRequestParameter which uses $request->getParsedBody(). $request->getParsedBody() returns NULL when parsing JSON unless the Body Parsing Middleware is included in the application.
Can I suggest that the documentation for this library is updated to include a reference to the Body Parsing Middleware requirement?
Can I suggest that the documentation for this library is updated to include a reference to the Body Parsing Middleware requirement?
Go ahead and send a patch to the docs, please :+1:
#40 is now merged. Thanks.