It happens sometimes that the Access Tokens of the users are considered invalid, but when we refresh the new Access Token is valid.
I just rely on ExpirationDate to check wether the AccessToken is invalid or not.
I saw this open topic: Invalid access token without reason (Solved) - App Development - Pipedrive Developers’ Community
I’m not sure but it could be that different places of the platform generated different access token, and only one is saved.
Could this be the issue? Or are there any potential other problems?
Any suggestions?
I want to pipe in here because I have had to handle similar scenarios.
From what I’ve seen the access token can devalidate at any time for different reasons. This shouldn’t always be the case but it can happen for a number of reasons:
- Another instance in your app runs the token asynchronously.
- The user started the oAuth flow again and reset the token.
I’ve noticed that if you run the the oauth endpoint to refresh the access token it will always change even if it’s still valid.
It really depends a lot on the design of your application. If you’re running multiple instances at once handling the same access tokens, etc. If that’s the case it’s always best to catch the error, and refresh it, then update the database while at the time time creating a mutex lock across all instances (like with Redis) to prevent multiple instances from starting a race condition.
That said, even in an app where the above doesn’t apply it’s always best practice to catch any expired token errors (from any API call you’re doing) and refreshing it, then re-running the API call again with the new token. This way it always refreshes and continues without crashing the action the user is doing.
This doesn’t really answeryour question completely but the best way to handle this is never trust the TTL on the token since that can change at any time and it’s best not to leave it up to chance.
Thank you @clintonskakun for the reply!
Yes I’ve already adopted these improvements and it seems to work fine now.
It was just weird and unclear to me, this behavior, but probably there were several flows working together and the update of the token could generate conflicts, invalidating the old one that was stored.
I integrate with several CRMs via OAuth, but this happened only to Pipedrive