GrantType Parse Exception

Issue #86 invalid
ShengChe Hsiao created an issue

I try to implement OAuth2 TOKEN Endpoint with java servlet, the sample code as follows

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            final HTTPRequest httprequest = new HTTPRequest(request);
            final TokenRequest tokenrequest = TokenRequest.parse(httprequest);
            AuthorizationGrant ag = tokenrequest.getAuthorizationGrant();
            System.out.println("Grant Type : " + ag.getType().getValue());
            final ClientSecretBasic clientsecretbasic = (ClientSecretBasic)tokenrequest.getClientAuthentication();
            System.out.println("Client ID : " + clientsecretbasic.getClientID() + " Client Secret : " + clientsecretbasic.getClientSecret().getValue());

        } catch (ParseException | IOException ex) {
            System.out.println(ex);
        }
    }

When I using Google OAuth2 Playground to fetch the token , it failed and show error message below:

com.nimbusds.oauth2.sdk.ParseException: Unsupported grant type: authorization_code

But when I look back to the source code, I could not figure what's wrong. The attachments it the log.

Comments (7)

  1. Vladimir Dzhuvinov

    I'm not able to reproduce the exception, despite adding a number of extra tests to check the GrantType equality method.

    Could you do a print out of the HTTP request URL, parameters and body, and post them here?

    Cheers,

    Vladimir

  2. ShengChe Hsiao reporter

    Dears

    I found the problem, that's HTTPRequest object add line separator as described in Issue #81.

    So if I put the grant_type parameter at tail, the parser will raise the exception!

  3. Log in to comment