Skip to content

Invalid_Grant Error #128

@aniespica

Description

@aniespica

For some of our clients twice a week the refresh token ends with invalid_grant. We contact them and request to re-authenticate to get new access & refresh token. It is annoying that it happened and we don't know how to handle it in the code.

Currently, our flow is:

  1. A function that interacts with QuickBooks API is called.
  2. The function loads the OAuth token from our database.
  3. If the access token is expired, we request a new token using the refresh token
const QuickbooksOauthClient = require("intuit-oauth");
const quickbooksOauthClient = new QuickbooksOauthClient(getOauthConfig());
const response = await quickbooksOauthClient.refreshUsingToken(clientsCredentials.RefreshToken); 
  1. The new token and refresh token are saved in our database.
  2. The API is called.

But for a few of our clients the refreshUsingToken() method response with invalid_grant. The following is a response for one of our clients with this issue:

     {
          "url": "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer",
          "headers": {
              "date": "Thu, 26 May 2022 05:11:00 GMT",
              "content-type": "application/json;charset=utf-8",
              "content-length": "25",
              "connection": "close",
              "intuit_tid": "1-628f0be4-19ed5ea63980105102b16b1e",
              "x-spanid": "4ed3e0e2-45a2-47bd-bae5-06c8024b8583",
              "x-amzn-trace-id": "Root=1-628f0be4-19ed5ea63980105102b16b1e",
              "x-content-type-options": "nosniff",
              "server": "envoy",
              "cache-control": "no-cache, no-store",
              "pragma": "no-cache",
              "x-envoy-upstream-service-time": "35",
              "strict-transport-security": "max-age=31536000"
          },
          "body": "{\"error\":\"invalid_grant\"}",
          "status": 400,
          "statusText": "Bad Request"
      }

What can we do to handle this issue by code?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions