As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

google_auth_oauthlib.helpers module

Integration helpers.

This module provides helpers for integrating with requests-oauthlib. Typically, you’ll want to use the higher-level helpers in google_auth_oauthlib.flow.

google_auth_oauthlib.helpers.credentials_from_session(session, client_config=None)[source]

Creates google.oauth2.credentials.Credentials from a requests_oauthlib.OAuth2Session.

fetch_token() must be called on the session before before calling this. This uses the session’s auth token and the provided client configuration to create google.oauth2.credentials.Credentials. This allows you to use the credentials from the session with Google API client libraries.

Parameters
  • session (requests_oauthlib.OAuth2Session) – The OAuth 2.0 session.

  • client_config (Mapping[str, Any]) – The subset of the client configuration to use. For example, if you have a web client you would pass in client_config[‘web’].

Returns

The constructed credentials.

Return type

google.oauth2.credentials.Credentials

Raises

ValueError – If there is no access token in the session.

google_auth_oauthlib.helpers.session_from_client_config(client_config, scopes, **kwargs)[source]

Creates a requests_oauthlib.OAuth2Session from client configuration loaded from a Google-format client secrets file.

Parameters
  • client_config (Mapping[str, Any]) – The client configuration in the Google client secrets format.

  • scopes (Sequence[str]) – The list of scopes to request during the flow.

  • kwargs – Any additional parameters passed to requests_oauthlib.OAuth2Session

Raises

ValueError – If the client configuration is not in the correct format.

Returns

The new

oauthlib session and the validated client configuration.

Return type

Tuple[requests_oauthlib.OAuth2Session, Mapping[str, Any]]

google_auth_oauthlib.helpers.session_from_client_secrets_file(client_secrets_file, scopes, **kwargs)[source]

Creates a requests_oauthlib.OAuth2Session instance from a Google-format client secrets file.

Parameters
  • client_secrets_file (str) – The path to the client secrets .json file.

  • scopes (Sequence[str]) – The list of scopes to request during the flow.

  • kwargs – Any additional parameters passed to requests_oauthlib.OAuth2Session

Returns

The new

oauthlib session and the validated client configuration.

Return type

Tuple[requests_oauthlib.OAuth2Session, Mapping[str, Any]]