Our integration has accessToken and refreshToken that we use to make queries to HubSpot. These tokens are needed to be updated from time to time, we update both when accessToken expires because refreshToken has better longevity.
But for some reason Hubspot gives us an error at some point BAD_REFRESH_TOKEN for refreshToken even though we updated both tokens not long ago. Could you please tell me why is this happening?
For example:
We used refreshToken [token here] to update acccessToken [token here]
We made a query at 2023-10-03T10:49:38.000Z (gmt +0).
Hi @Onimi,
Thank you for checking with the Community!
I’d like to invite some top experts to this conversation: Hi @mangelet, @Mike_Eastwood and @ChrisoKlepke do you have suggestions to help @Onimi and @Onimidori, please? Also, if anybody else has anything to add and/or share, please feel free to join in the conversation
Thanks a lot and have a wonderful day!
Bérangère
Thank you, Bérangère. Unfortunately these topics are not related to us. We have such issue with multiple clients and I doubt every one of them decided to uninstall our application out of blue
@Onimidori Alright, let me give you a hand. When you’re working with the standard OAuth flow, you’ll receive three things in the same response the first time you get your tokens. You’ll get the access token, the refresh token, and the expiration time. That’s the moment when you need to renew your access token.
Now, that expiration time might be something you’re not paying attention to at the moment. It’s crucial for knowing exactly when your access token will expire, without any guesswork.
So, give it a try. Save that information and proactively request a new access token before that expiration time comes.
As a developer, it’s your responsibility to store this data, persist it, and make sure to do this asynchronously before it expires.
If you follow these steps correctly, you shouldn’t face any issues. However, there might be something in your code that isn’t following the standard OAuth authentication flow.
Take another look at your code and see if this new information helps you identify the issue. Good luck!
you’ll receive three things in the same response the first time you get your tokens. You’ll get the access token, the refresh token, and the expiration time. That’s the moment when you need to renew your access token.
Thank you for reaching out. We know about expiration time, this is the actual problem. We look at expiration time, update both tokens and receive an error that refreshToken became invalid, how is that possible? Expiration of refreshToken cant become before expiration of accessToken, accessToken should always invalidate first, but for some reason its refreshToken, could you please take a look once again?
Hi @Onimi1, I hope that you are well!
Thank you for your patience as I was checking on this internally.
I checked for you and this type of error most frequently happens when the app is uninstalled from a portal, please see this post here for your reference.
When integration is uninstalled, that will invalidate the refresh token. You’d need to re-install the integration, where you can then exchange the auth code for a new refresh token.
So, reinstalling the app to generate a new token should solve this.
Please let me know if you still see the same behavior after this.
Thanks and have a great weekend!
Best,
Bérangère
What about situations when app was not touched?
Could you please look through a concrete example that I’ve sent in the original post and tell me whether the integration was or was not uninstalled? Because the client claims they did not and I tend to believe it since there was no reason to randomly delete the app from Hubspot
Hi @Onimi1, I hope that you are well!
I was checking internally for you. Thanks for your patience!
1. Have you considered generating a new token as recommended by @cbarley on this post? Do you have an option to reauthorized the app?
2. If there is no existing refresh tokens. It can be for the following reasons:
- The app was uninstalled => you mentionned it was not the case
- The portal was purged and therefore the refresh tokens associated with the portal were also deleted.
3. Did you check the code as mentioned in previous posts? Thank you for your help @mangelet !!! It may be that “your code that isn’t following the standard OAuth authentication flow”.
Here is a documentation about Oauth Access that can help you.
Thank you and have a good day!
Best,
Bérangère
Hello, as I mentioned multiple times above the problem was not in app deleting.
The post that you’ve linked is about accessToken being invalidated, while I have another problem - refreshToken invalidates sooner than in should, please take a look at the example that I’ve shown in OP.
According to your doc, refreshToken is used to update accessToken which means refreshToken lives longer. When the time comes to refresh accessToken we refresh both just in case so its not clear how a new refreshToken can be invalidated before the accessToken.
it is still happens from time to time
Hi @Onimi1,
Thank you for your patience as I was out of the office.
I have sent you a private message. Can you please review it and send me a reply via direct message?
Thanks a lot!
Best,
Bérangère