# refreshToken becomes invalid too fast

**URL:** <https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181>\
**Category:** APIs & Integrations\
**Tags:** timeline-and-extensions-apis\
**Created:** [October 5, 2023, 12:51pm UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181 "2023-10-05T12:51:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onimidori](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@Onimidori](https://community.hubspot.com/u/Onimidori)\
**Post date:** [October 5, 2023, 12:51pm UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/1 "2023-10-05T12:51:25Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [October 10, 2023, 10:34am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/2 "2023-10-10T10:34:29Z")

</div>

Hi @Onimidori,  
Thank you for reaching out to the Community!  
I’d like to share these resources that might be of interest to you:  
- [BAD\_REFRESH\_TOKEN error when attempting to refresh access token](https://community.hubspot.com/t5/APIs-Integrations/BAD-REFRESH-TOKEN-error-when-attempting-to-refresh-access-token/m-p/248823)  
- [BAD\_REFRESH\_TOKEN while trying to refresh token](https://community.hubspot.com/t5/APIs-Integrations/BAD-REFRESH-TOKEN-while-trying-to-refresh-token/m-p/369120)  
- [What to do when you suddenly get BAD\_REFRESH\_TOKEN when trying to refresh an access token](https://community.hubspot.com/t5/APIs-Integrations/What-to-do-when-you-suddenly-get-BAD-REFRESH-TOKEN-when-trying/m-p/241622)  
I also wanted to invite a couple of subject matter experts to this conversation @ChristinaKay, @louischausse and @Teun do you have suggestions to help @Onimidori, please?  
**If anybody else has anything to add and/or share, please feel free to join in the conversation** 🙂  
Thanks and have a lovely day!  
Best,  
Bérangère

---

<div class="post-metadata">

**Author:** ![Onimi](https://avatars.discourse-cdn.com/v4/letter/o/a5b964/32.png) [@Onimi](https://community.hubspot.com/u/Onimi)\
**Post date:** [November 2, 2023, 8:44am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/3 "2023-11-02T08:44:22Z")

</div>

any update please? Did you manage to fix it?

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [November 2, 2023, 11:05am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/4 "2023-11-02T11:05:21Z")

</div>

Hi @Onimi,  
Thank you for checking with the Community!  
I’d like to invite some top experts to this conversation: Hi @mangelet, [@Mike\_Eastwood](https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259) 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

---

<div class="post-metadata">

**Author:** ![Onimidori](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@Onimidori](https://community.hubspot.com/u/Onimidori)\
**Post date:** [October 11, 2023, 7:48am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/5 "2023-10-11T07:48:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mangelet](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mangelet/32/83031_2.png) [@mangelet](https://community.hubspot.com/u/mangelet)\
**Post date:** [November 2, 2023, 12:47pm UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/6 "2023-11-02T12:47:30Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![Onimi](https://avatars.discourse-cdn.com/v4/letter/o/a5b964/32.png) [@Onimi](https://community.hubspot.com/u/Onimi)\
**Post date:** [November 13, 2023, 6:51am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/7 "2023-11-13T06:51:23Z")

</div>

> * * *
> 
> 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?

---

<div class="post-metadata">

**Author:** ![Onimi](https://avatars.discourse-cdn.com/v4/letter/o/a5b964/32.png) [@Onimi](https://community.hubspot.com/u/Onimi)\
**Post date:** [November 15, 2023, 9:44am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/8 "2023-11-15T09:44:50Z")

</div>

any update please? This is crucial because it affects the users

---

<div class="post-metadata">

**Author:** ![Onimi1](https://avatars.discourse-cdn.com/v4/letter/o/7ea924/32.png) [@Onimi1](https://community.hubspot.com/u/Onimi1)\
**Post date:** [November 22, 2023, 8:12am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/9 "2023-11-22T08:12:27Z")

</div>

Hello?

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [November 24, 2023, 5:03pm UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/10 "2023-11-24T17:03:49Z")

</div>

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](https://community.hubspot.com/t5/APIs-Integrations/BAD-REFRESH-TOKEN-error-when-attempting-to-refresh-access-token/m-p/248823)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.

If you are developer creating apps, I would also recommend joining our [Slack Channel for developers](https://developers.hubspot.com/slack#:~:text=HubSpot's%20Developer%20Slack%20is%20a,collaboration%20around%20the%20HubSpot%20platform).

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

---

<div class="post-metadata">

**Author:** ![Onimi1](https://avatars.discourse-cdn.com/v4/letter/o/7ea924/32.png) [@Onimi1](https://community.hubspot.com/u/Onimi1)\
**Post date:** [November 27, 2023, 6:13am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/11 "2023-11-27T06:13:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [November 30, 2023, 11:18am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/12 "2023-11-30T11:18:19Z")

</div>

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](https://community.hubspot.com/t5/APIs-Integrations/BAD-REFRESH-TOKEN-error-when-attempting-to-refresh-access-token/m-p/248823)? 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](https://legacydocs.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens) that can help you.  
Thank you and have a good day!  
Best,  
Bérangère

---

<div class="post-metadata">

**Author:** ![Onimi1](https://avatars.discourse-cdn.com/v4/letter/o/7ea924/32.png) [@Onimi1](https://community.hubspot.com/u/Onimi1)\
**Post date:** [December 1, 2023, 10:12am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/13 "2023-12-01T10:12:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [December 5, 2023, 11:30am UTC](https://community.hubspot.com/t/refreshtoken-becomes-invalid-too-fast/91181/14 "2023-12-05T11:30:43Z")

</div>

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
