intuit / oauth-jsclient

Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
https://developer.intuit.com/
Apache License 2.0
121 stars 156 forks source link

Consistently getting `Response has an Error` when revoking token #71

Closed ekscentrysytet closed 4 years ago

ekscentrysytet commented 4 years ago

Hello! When I call oauthClient.revoke() I keep getting Response has an Error error message with 400 status. My sample code is following:

const initQBOAuthClient = token => new OAuthClient({
    clientId: quickbooks.clientId,
    clientSecret: quickbooks.clientSecret,
    environment: quickbooks.sandbox ? 'sandbox' : 'production',
    redirectUri: quickbooks.redirectUri,
    token,
});

const oauthClient = initQBOAuthClient({
        token_type: 'bearer',
        access_token: accessToken,
        expires_in: 3600,
        refresh_token: refreshToken,
        x_refresh_token_expires_in: xRefreshTokenExpiresIn,
});

try {
        await oauthClient.revoke();
} catch (e) {
        console.log('revoke error', e);
        throw e;
}

The result if following:

revoke error { Error: Response has an Error
error: 'Bad Request',
   authResponse:
    AuthResponse {
      token:
       Token {
         realmId: '',
         token_type: 'bearer',
         access_token:
          'XXX',
         expires_in: 3600,
         x_refresh_token_expires_in: XXX,
         id_token: '',
         latency: 60000,
         createdAt: 1580113629212 },
      response:
       Response {
         Url: [Url],
         rawHeaders: [Array],
         body: '',
         status: 400,
         statusText: 'Bad Request' },
      body: '',
      json: null,
      intuit_tid: 'XXX' },
   intuit_tid: 'XXX',
   originalMessage: 'Response has an Error',
   error_description: 'Bad Request' }

Any ideas?

ekscentrysytet commented 4 years ago

However some time after (like 2-3 mins) when I remove code that revokes token and making API requests to QB I'm getting error that token is revoked.

{"warnings":null,"intuitObject":null,"fault":{"error":[{"message":"message=AuthenticationFailed; errorCode=003200; statusCode=401","detail":"Token revoked","code":"3200","element":null}],"type":"AUTHENTICATION"},"report":null,"queryResponse":null,"batchItemResponse":[],"attachableResponse":[],"syncErrorResponse":null,"requestId":null,"time":1580114174171,"status":null,"cdcresponse":[]}
abisalehalliprasan commented 4 years ago

@ekscentrysytet : Are you sure the access/refresh token was not revoked already? If the token is already revoked and you perform a revoke on it, the library would throw the Bad Request error similar to what you have posted above.

Could you provide the intuit-tid from the response headers if you are still getting the same error, I could verify the token validity?

ekscentrysytet commented 4 years ago

@abisalehalliprasan You're right, I had two concurrent requests and in one of them I revoked a token and on another I got that error. Thanks! Closing now