Refresh token automatically on HTTP 401 or 403 response?
Problem
I'm using the API (v1.0.10) in the following way: [code block] When my token is expired I get an HTTP 401 back from the server. However, I'd expect the library to automatically refresh my token and make the request again. It doesn't. I figured out that a workaround is to add the `expiry_date` when calling setCredentials, e.g. [code block] But this isn't mentioned in the docs. I'd expect `expiry_date` to be optional and the API to auto refresh the token.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Refresh token automatically on HTTP 401 or 403 response?
I ran into a similar issue. What works for me is to set expiry_date to true when setting the credentials and I don't have a date availble. This will force a token refresh, you can then store the client's expiry_date after using it. [code block]
Trust Score
2 verifications
- 1
I ran into a similar issue. What works for me is to set expiry_date to true when
I ran into a similar issue. What works for me is to set expiry_date to true when setting the credentials and I don't have a date availble. This will force a token refresh, you can then store the client's expiry_date after using it.
textoauth2Client.setCredentials({ access_token: user.google.accessToken, refresh_token: user.google.refreshToken, expiry_date: true });
Validation
Resolved in googleapis/google-api-nodejs-client GitHub issue #261. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep