Skip to content
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

Inappropriate error code 'unsupported_grant_type' during authorization request #1216

Open
cicnavi opened this issue Apr 20, 2021 · 2 comments

Comments

@cicnavi
Copy link

cicnavi commented Apr 20, 2021

Hi, thank you for your wonderful work on oauth2-server package.

According to OAuth 2.0 spec for errors during authorization request, authorization server should return error 'unsupported_response_type' if the response_type parameter is invalid (missing, unsupported value...). The current implementation returns error code 'unsupported_grant_type', which is not in accordance to the spec.

The only place in spec where I see error code 'unsupported_grant_type' is in section 5. Issuing an Access Token.

So, as I understand it, the error code 'unsupported_response_type' should be related to the 'response_type' parameter which is used in authorization request. The error code 'unsupported_grant_type' should be related to the 'grant_type' type parameter which is used in token request.

Best regards

@Sephster
Copy link
Member

Sephster commented May 15, 2021

Thanks @cicnavi - this is an interesting one. We don't specifically ever check for the response_type parameter in the way the oauth 2 spec expects. If a client sends in an authorization request, the server retrieves all enabled grant types, and checks against each one whether it can respond to an auth request.

public function validateAuthorizationRequest(ServerRequestInterface $request)
    {
        foreach ($this->enabledGrantTypes as $grantType) {
            if ($grantType->canRespondToAuthorizationRequest($request)) {
                return $grantType->validateAuthorizationRequest($request);
            }
        }

        throw OAuthServerException::unsupportedGrantType();
    }

In the case of the authcode grant, we check if a response_type has been set, if that is set to code, and if a client ID has been set. If any of these aren't satisfied, we assume the client didn't want to use this grant but they might have wanted to use another one...

If we can't find any grants that can run the type of auth request the client has sent, we return unsupported_grant_type.

I will need to look into it more but I think the challenge would be definitely knowing the client meant to use a particular grant as we don't have endpoints for each type.

@cicnavi
Copy link
Author

cicnavi commented May 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants