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.OAuth2Sessionfrom 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 –
Anyadditional parameters passed torequests_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] ]- client_config (
-
session_from_client_secrets_file(client_secrets_file, scopes, **kwargs)[source]¶ Creates a
requests_oauthlib.OAuth2Sessioninstance 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 –
Anyadditional parameters passed torequests_oauthlib.OAuth2Session
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.Credentialsfrom arequests_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 creategoogle.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: Raises: ValueError– If there is no access token in the session.