Need clear the refresh token workflow.
See original GitHub issueI want to store the tokens
in my database and before call google apis, I want use refresh_token
to get a new access_token
so that user don’t need redirect to the consent screen.
Here is my workflow:
router.get('/oauth/callback', async (req, res) => {
const { code: authorizationCode } = req.query;
const { tokens } = await oauth2Client.getToken(authorizationCode);
oauth2Client.setCredentials(tokens);
// store tokens in database
db.save(tokens);
//...
});
And, before every google api call, I will set refresh_token
to oauth2Client like this:
router.get('/plus/:userId', () => {
//get refresh token from database
db.get(tokens);
oauth2client.setCredentials({ refresh_token: tokens.refresh_token });
// call google+ api
const plus = google.plus("v1");
const { data } = await plus.people.get({ userId });
//...
})
- Is the workflow correct?
- Is it necessary to set
refresh_token
before every api call? - Should I check the expired time of
access_token
by myself? refreshAccessToken
is deprecated. Is that mean I don’t need refreshaccess_token
by myself?
Need clear the doc.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
What Are Refresh Tokens and How to Use Them Securely
This post will explore the concept of refresh tokens as defined by OAuth 2.0. We will learn how they compare to other token...
Read more >Using Refresh Tokens in ASP.NET Core Authentication
Refresh token -based authentication workflow · First, the client authenticates with the authentication component by providing the credentials ...
Read more >Refresh access tokens - Okta Developer
This guide explains how to refresh access tokens with Okta. Learning outcomes. Understand how to set up refresh token rotation. Refresh access tokens....
Read more >rest api - Understanding the refresh token workflow
There's a number of things you need to do to get everything just right. Under Setup > Create > Apps, go down to...
Read more >Refresh Tokens — IdentityServer4 1.0.0 documentation
Refresh tokens are supported for the following flows: authorization code, hybrid and resource owner password credential flow. The clients needs to be explicitly ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AVaksman Thanks for reply.
The
readme
says:I think the refresh token should be attached to a
user
context. Which means each user will have a refresh token. Which refresh token the library will automatically use? So I think I should set the refresh token to this library manually. Like below:The
tokens
event does not have auser
context. I think what @supertiger1234 said is the same thing.I use
express.js
, in order to get theuser
context of client request, which place should I put thistoken
event? The middleware or some global scope?If there is an sample using
express.js
for handling the expiring of access token. That will be great.After I read
readme
about ten times. I think maybesetCredentials
api can satisfy my requirement.Here is fake code to demonstrate the workflow:
@apoorva-shah a refresh token does not expire (or should expire very rarely, e.g., if a user revokes credentials on their account). If the goal is to perform background processing for a user with your application, store the
refresh_token
when first authorizing, and then use this when instantiating the client in the future (the auth library will handle refreshing the token automatically).