Skip to content

jam.oauth2.client

client

Classes:

Name Description
OAuth2Client

Universal OAuth2 client implementation.

OAuth2Client

OAuth2Client(
    client_id: str,
    client_secret: str,
    auth_url: str,
    token_url: str,
    redirect_url: str,
)

Bases: BaseOAuth2Client

Universal OAuth2 client implementation.

Methods:

Name Description
client_credentials_flow

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

fetch_token

Exchange authorization code for access token.

get_authorization_url

Generate full OAuth2 authorization URL.

refresh_token

Use refresh token to obtain a new access token.

__http

__http(url: str)

Create HTTPS connection context manager.

__post_form

__post_form(
    url: str, params: dict[str, Any]
) -> dict[str, Any]

Send POST form and parse JSON response.

client_credentials_flow

client_credentials_flow(
    scope: Optional[list[str]] = 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

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

Exchange authorization code for access token.

Parameters:

Name Type Description Default
code str

OAuth2 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

get_authorization_url

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

Generate full OAuth2 authorization URL.

Parameters:

Name Type Description Default
scope list[str]

Auth scope

required
extra_params Any

Extra ath params

{}

Returns:

Name Type Description
str str

Authorization url

refresh_token

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

Use refresh token to obtain a new 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]

Refresh token

FILE PATH: jam/oauth2/client.py