Grants¶
The OAuth2Grant
abstract class defines the high-level interface for OAuth 2.0 grant implementations.
The grant object should be used as an async context manager.
Common¶
- class aiohttp_oauth2_client.grant.common.OAuth2Grant(token_url: str | URL, token: dict | None = None, **kwargs)[source]¶
Bases:
object
Generic OAuth 2.0 Grant class.
- Parameters:
- async ensure_active_token()[source]¶
Ensure that the stored access token is still active. If this is not the case, the token will be refreshed.
- async execute_token_request(data: AccessTokenRequest) Token [source]¶
Execute a token request with the provided data.
- Parameters:
data (AccessTokenRequest) – token request data
- Returns:
OAuth 2.0 Token
- Raises:
OAuth2Error – if the token request fails
aiohttp.ClientResponseError – if the HTTP error cannot be parsed as an OAuth 2.0 error response
- Return type:
- async fetch_token()[source]¶
Fetch an OAuth 2.0 token from the token endpoint and store it for subsequent use.
Client Credentials¶
- class aiohttp_oauth2_client.grant.client_credentials.ClientCredentialsGrant(token_url: str | URL, client_id: str, client_secret: str, token: dict | None = None, **kwargs)[source]¶
Bases:
OAuth2Grant
OAuth 2.0 Client Credentials grant.
Use client credentials to obtain an access token.
https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
- Parameters:
- async refresh_token()[source]¶
Following the specification, the token response for the client credentials grant SHOULD NOT include a refresh token. The client credentials grant should be used to get a new access token when the previous one has expired.
https://datatracker.ietf.org/doc/html/rfc6749#section-4.4.3
Some clients may issue a refresh token for the client credentials flow, even though it is not correct according to the specification. In this case, the refresh token will be used to obtain a new access token.
Resource Owner Password Credentials¶
- class aiohttp_oauth2_client.grant.resource_owner_password_credentials.ResourceOwnerPasswordCredentialsGrant(token_url: str, username: str, password: str, token: dict | None = None, **kwargs)[source]¶
Bases:
OAuth2Grant
OAuth 2.0 Resource Owner Password Credentials grant.
Use the username and password of the resource owner to obatain an access token.
Device Code¶
- class aiohttp_oauth2_client.grant.device_code.DeviceCodeGrant(token_url: str | URL, device_authorization_url: str | URL, client_id: str, token: dict | None = None, pkce: bool = False, **kwargs)[source]¶
Bases:
OAuth2Grant
OAuth 2.0 Device Code grant.
Obtain user authorization on devices with limited input capabilities or lack a suitable browser to handle an interactive log in procedure. The user is instructed to review the authorization request on a secondary device, which does have the requisite input and browser capabilities to complete the user interaction.