INVALID_GRANT issue

Hello,

I’m getting INVALID_GRANT error on the first request after creating a token. I only have this problem for two days.

I use the same token until its validity period expires, I don’t generate tokens over and over again. When I generate a token, I’m using it immediately without waiting. It gives an INVALID_GRANT error but when I wait for some time it’s working fine.

Is there any problem on your side, maybe tokens are processing after generating a token response?

To give you full context: we run one MySQL server which acts as Primary, and all the writes go there. When you ask for a new token, it’s stored in the primary database. Then, we have a few (autoscaling) replicas. These replicas are used for read-only operations.

In the past, we have experienced during peak hours a data lag of 1-2 seconds between the primary database and the replicas. Because of this lag, when a new token is generated, it’s unlikely, but possible during peak hours, that the token is not available in the replicas, hence when doing any request, the first step is to run the authentication check. This uses the replica as it’s a read operation, and as the token is not yet there, it’ll return a 401.

In your case, what I would encourage you to do is to add a delay of a couple of seconds after receiving the new token, so that you give enough time for the token to be replicated in time on the replicas.

Thank you,

Thank you, please let me know when you fix it.

An update on the advice mentioned in this topic to:

The known issue of replica delay which was causing some integrators to experience “token revoked” errors has now been resolved on our platform. Although adding a delay as mentioned above will certainly cause no harm, it is no longer a requirement as the replica sync issue has been resolved at it’s core. Our tips and best practices regarding authentication can now be found in our related oAuth authentication post.

1 Like