Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does access token Expires #517

Closed
Chethandsagar opened this issue Feb 22, 2016 · 4 comments
Closed

Does access token Expires #517

Chethandsagar opened this issue Feb 22, 2016 · 4 comments
Assignees

Comments

@Chethandsagar
Copy link

I'm using the API (v1) in the following way:

var oauth2Client = new OAuth2(getGoogleCredentials().clientId, getGoogleCredentials().secret);
oauth2Client = new OAuth2(this.clientId, this.clientSecret);
this.oauth2Client.setCredentials({
  access_token: this.access_token,
  refresh_token: this.refresh_token,
  expiry_date: true
});

never got the 401 or 403 response .
currently i see the behavior that access token may be automatically refreshes.

  1. Does gmail Api automatically refreshes the access token?
  2. How do i hit with 401 & 403 response and how the gmail api refreshes it?
@jmdobry
Copy link
Contributor

jmdobry commented Mar 4, 2016

  1. Does gmail Api automatically refreshes the access token?

Yes, that should be the case. From README.md:

OAuth2 client that allows you to retrieve an access token and refreshes the token and retry the request seamlessly if token is expired.

  1. How do i hit with 401 & 403 response and how the gmail api refreshes it?

If the OAuth2 client discovers that the access token is expired, then it should automatically refresh the token. You won't see the 401 or 403 for an expired token.

@ryanseys Can confirm.

@jmdobry
Copy link
Contributor

jmdobry commented Mar 4, 2016

Closing as this does not appear to be an issue. If you are convinced that this is really a bug, please feel free to re-open the issue and add more information such as:

  • Expected behavior
  • Actual behavior
  • Code samples
  • Version numbers
  • References docs or other links

Or, consider opening a Pull Request.

Otherwise, support questions are handled on Stack Overflow. Ask a question on Stackoverflow

@jmdobry jmdobry closed this as completed Mar 4, 2016
@nikitaeverywhere
Copy link

nikitaeverywhere commented May 8, 2016

If the OAuth2 client discovers that the access token is expired, then it should automatically refresh the token. You won't see the 401 or 403 for an expired token.

Having oauth2Client,

Does anyone know the way to check if the token was refreshed and get a new one? I have never found this in the docs. This stands for a common reason — I want to keep always up-to-date token in my database.

Thanks!

UPD

The one way I found for now is the next one:

let storedToken = { access_token: "...", expiry_date: 0000, ... };
oauth2Client.getAccessToken((err, access_token) => {
  if (storedToken.access_token !== access_token) {
    Object.assign(storedToken, oauth2Client.credentials || {});
  }
  // next steps go here
})

And there is no other way to access oauth2Client.credentials than directly. I suggest creating and documenting getter for this, what do you think?

@Alex-Mann
Copy link

I also face the same issue. I was originally going call oauth2Client.refreshAccessToken() manually and save the updated token, but it seems that this method is deprecated.

Is the method that @ZitRos posted the elegant solution or has someone discovered a better way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants