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.

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:
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 ] ]

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:
Returns:

The new

oauthlib session and the validated client configuration.

Return type:

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

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.