APIs & Integrations

fregini
Participant | Diamond Partner
Participant | Diamond Partner

OAuth refresh token does not refresh

SOLVE

Hi, 

I notice a weird behaviour when refreshing the OAuth token. Here's what I'm doing: 

 

1. when first connecting the APP via OAuth, I save the auth_token and refresh_token. 

2. I use the oauth_token for API calls, everything works fine. 

3. When I get 401 from API calls, I make an API call to refresh the token and get the new token. 

4. This API call to refresh the token fails with the following message: 

 

[2019-08-26T22:11:54+00:00] ERROR: HTTP Code 401; message: This oauth-token (*tokenstring_omitted*) is expired! expiresAt: 1566857360235, now: 1566857513926

 

Is anyone else experiencing the same issue? Any advice? 

0 Upvotes
1 Accepted solution
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

OAuth refresh token does not refresh

SOLVE

Hello @fregini 

 

It would be a good practice to save the expiration time of oauth token and checking its validity before making any API call to HubSpot. If the expiration time remain valid then you can continue with API call but if it fails we can go for refresh token API call. The best method would be refreshing the oauth token with the help of access token few seconds before it gets expired. It will never lead to such 401 conditions.

 

Thanks

Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

0 Upvotes
2 Replies 2
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

OAuth refresh token does not refresh

SOLVE

Hello @fregini 

 

It would be a good practice to save the expiration time of oauth token and checking its validity before making any API call to HubSpot. If the expiration time remain valid then you can continue with API call but if it fails we can go for refresh token API call. The best method would be refreshing the oauth token with the help of access token few seconds before it gets expired. It will never lead to such 401 conditions.

 

Thanks

Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
fregini
Participant | Diamond Partner
Participant | Diamond Partner

OAuth refresh token does not refresh

SOLVE

Hi, I've found the issue it was a bug in my procedure for token refresh. Refreshing the token does not result in any issue anymore. 

 

About your advice, yes, that's more sound approach, I'll change my code accoringly and keep the fallback on 401 anyway in case anything goes wrong.