Skip to content

Obtaining and storing a new access token. #42

Description

@davetapley

Building on #14, I see that when you ask for offline_access and you have refresh_token then we get the behavior:

If you provide a refresh_token, in cases when access_token is expired, it asks for a new access_token and replays the request.

Presumably we would be wise to obtain and store the new access_token to use in the future?
I don't see this mentioned in the existing documentation.

Activity

  1. rakyll commented on May 20, 2013

    @rakyll
    Contributor

    You need to preserve the refresh_token, you can retrieve it once and need to persist. Even if you don't provide an access token, client will fetch a new one.

  2. davetapley commented on May 20, 2013

    @davetapley
    Author

    Okay, so we don't expect the refresh_token to change, ever (unless you approval_prompt and get a new one), which is consistent with these docs and this code.

    So for an ongoing offline task, I see two options:

    1. Don't store an access_token, and let OAuth2Client get a new one on every request.
    2. Store and set oauth2Client.credentials.access_token, and on the completion of every request (via execute) store a (potentially updated) oauth2Client.credentials.access_token.

    Where the advantage of the second option is:

    If the access_token is still valid, then you'll save a HTTP request (to get a new access_token) for every request you make.

    Looking at the OAuth2 playground an access_token expires in 4000 seconds. So if you're making more than one request per hour, it's probably worth using option 2, otherwise you'll make just as many requests with option 1 (and you won't need to persist access_token).

  3. rakyll commented on May 21, 2013

    @rakyll
    Contributor

    You're right. If you make more than one request in 4000 secs, it's better to go with the second option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions