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

feat: support refresh callable on google.oauth2.credentials.Credentials #812

Merged
merged 3 commits into from Jul 22, 2021
Merged

feat: support refresh callable on google.oauth2.credentials.Credentials #812

merged 3 commits into from Jul 22, 2021

Commits on Jul 21, 2021

  1. feat: support refresh handler callable on google.oauth2.credentials.C…

    …redentials
    
    This is an optional parameter that can be set via the constructor.
    It is used to provide the credentials with new tokens and their
    expiration time on `refresh()` call.
    
    ```
    def refresh_handler(request, scopes):
        # Generate a new token for the requested scopes by calling
        # an external process.
        return (
            "ACCESS_TOKEN",
            _helpers.utcnow() + datetime.timedelta(seconds=3600))
    
    creds = google.oauth2.credentials.Credentials(
        scopes=scopes,
        refresh_handler=refresh_handler)
    creds.refresh(request)
    ```
    
    It is useful in the following cases:
    - Useful in general when tokens are obtained by calling some
      external process on demand.
    - Useful in particular for retrieving downscoped tokens from a
      token broker.
    
    This should have no impact on existing behavior. Refresh tokens
    will still have higher priority over refresh handlers.
    
    A getter and setter is exposed to make it easy to set the callable
    on unpickled credentials as the callable cannot be easily serialized.
    
    ```
    unpickled = pickle.loads(pickle.dumps(oauth_creds))
    unpickled.refresh_handler = refresh_handler
    ```
    bojeil-google committed Jul 21, 2021
    Configuration menu
    Copy the full SHA
    271f43b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a76a365 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0064270 View commit details
    Browse the repository at this point in the history