Skip to content

jam.aio.oauth2.base

__base__

Classes:

Name Description
BaseAsyncOAuth2Client

Base async OAuth2 client instance.

BaseAsyncOAuth2Client

BaseAsyncOAuth2Client(
    client_id: str,
    client_secret: str,
    auth_url: str,
    token_url: str,
    redirect_url: str,
    serializer: BaseEncoder
    | type[BaseEncoder] = JsonEncoder,
)

Bases: ABC

Base async OAuth2 client instance.

Parameters:

Name Type Description Default
client_id str

ID or your client

required
client_secret str

Secret key for your application

required
auth_url str

App auth url

required
token_url str

App token url

required
redirect_url str

Your app url

required
serializer Union[BaseEncoder, type[BaseEncoder]]

JSON encoder/decoder. Defaults to JsonEncoder.

JsonEncoder

Methods:

Name Description
client_credentials_flow

Obtain access token using client credentials flow (no user interaction).

fetch_token

Exchange code for access token.

get_authorization_url

Get OAuth2 url.

refresh_token

Update access token.

client_credentials_flow abstractmethod async

client_credentials_flow(
    scope: list[str] | None = None, **extra_params: Any
) -> dict[str, Any]

Obtain access token using client credentials flow (no user interaction).

Parameters:

Name Type Description Default
scope list[str] | None

Auth scope

None
extra_params Any

Extra auth params if needed

{}

Returns:

Name Type Description
dict dict[str, Any]

JSON with access token

fetch_token abstractmethod async

fetch_token(
    code: str,
    grant_type: str = "authorization_code",
    **extra_params: Any,
) -> dict[str, Any]

Exchange code for access token.

Parameters:

Name Type Description Default
code str

Auth code

required
grant_type str

Type of oauth2 grant

'authorization_code'
extra_params Any

Extra auth params if needed

{}

Returns:

Name Type Description
dict dict[str, Any]

OAuth2 token response

get_authorization_url abstractmethod async

get_authorization_url(
    scope: list[str], **extra_params: Any
) -> str

Get OAuth2 url.

Parameters:

Name Type Description Default
scope list[str]

Auth scope

required
extra_params Any

Extra auth params

{}

Returns:

Name Type Description
str str

URL for auth

refresh_token abstractmethod async

refresh_token(
    refresh_token: str,
    grant_type: str = "refresh_token",
    **extra_params: Any,
) -> dict[str, Any]

Update access token.

Parameters:

Name Type Description Default
refresh_token str

Refresh token

required
grant_type str

Grant type

'refresh_token'
extra_params Any

Extra auth params if needed

{}

Returns:

Name Type Description
dict dict[str, Any]

New token response