Skip to content

OAuth2Client.getToken returns empty error, no token #350

Closed

Description

@akashgupta88

Hi, I am trying to get the access_token using the OAuth2Client's getToken method.

var oauth2Client = new OAuth2(clientID, clientSecret);

oauth2Client.getToken(authCode, function (err, tokens) {
    console.log(JSON.stringify(err), tokens);
}

The following is getting logged:

{} null

However, I sent a POST request to https://accounts.google.com/o/oauth2/token separately with the payload:

{
    code: <authCode>,
    client_id: <clientId>,
    client_secret: <clientSecret>,
    grant_type: authorization_code
}

And it returned the access_token, refresh_token as requested.

Why is the error object empty, and what could be the issue?

Activity

  1. akashgupta88 commented on Jan 16, 2015

    @akashgupta88
    Author

    I tried logging the response in the wrapCallback_ method in transporter.js.

    //Transporter.js, line 64
    DefaultTransporter.prototype.wrapCallback_ = function(opt_callback) {
      return function(err, res, body) {
        console.log(err, res, body);
        ...
    

    And the body was logged as:

     body: 
       { error: 'invalid_grant',
         error_description: 'Code was already redeemed.' } }
    

    This was to happen as I have been testing this with the same code. However, this error message was not reaching the original callback. This is because of the line:

    //Transporter.js, line 76
    if (body && body.error) {
      // handle single request errors
      err = new Error(body.error.message);
      err.code = body.error.code;
      body = null;
    }
    

    As you can see, the error object returned does not match the one this code expects.

  2. akashgupta88 commented on Jan 16, 2015

    @akashgupta88
    Author

    This issue has been resolved with pull request #351

  3. stephen commented on Jan 16, 2015

    @stephen
    Contributor

    Well, still pending review/merge, but glad that I'm not the only one who ran into this 😄.

  4. ryanseys commented on Jan 19, 2015

    @ryanseys
    Contributor

    @akashgupta88 Released the fix in v1.1.1 available now on npm.

  5. FahadTariq476-dev commented on Oct 28, 2020

    @FahadTariq476-dev

    my token.js showing null what i am doing wrong???

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

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions