SlyAPI.oauth2#

Implementation for OAuth2.0 with PKCE as the Auth interface https://datatracker.ietf.org/doc/html/rfc7636

Functions

command_line_oauth2(app, redirect_host, ...)

requires_scopes(*_scopes)

Mark a endpoint as requiring specific scopes to be used

Classes

OAuth2(app, user[, on_refresh])

Provides the Auth interface implementation for OAuth2

OAuth2App(id, secret, auth_uri, token_uri)

OAuth2User(token, refresh_token, expires_at, ...)

SlyAPI.oauth2.requires_scopes(*_scopes)[source]#

Mark a endpoint as requiring specific scopes to be used

Parameters:

_scopes (str) –

Return type:

Callable[[Callable[[~F_Params], F_Return]], Callable[[~F_Params], F_Return]]

class SlyAPI.oauth2.OAuth2User(token: str, refresh_token: str, expires_at: datetime.datetime, token_type: str = 'Bearer', scopes: list[str] = <factory>)[source]#

Bases: object

Parameters:
token: str#
refresh_token: str#
expires_at: datetime#
token_type: str = 'Bearer'#
scopes: list[str]#
classmethod from_json_obj(obj)[source]#

Read an app from a JSON object

Parameters:

obj (Mapping[str, int | float | bool | str | None | datetime | date | time | Sequence[TomlType] | Mapping[str, TomlType]]) –

Return type:

OAuth2User

classmethod from_json_file(path)[source]#

Read an app from a JSON file path

Parameters:

path (str) –

Return type:

OAuth2User

to_dict()[source]#
Return type:

dict[str, Any]

class SlyAPI.oauth2.OAuth2App(id: str, secret: str, auth_uri: str, token_uri: str)[source]#

Bases: object

Parameters:
  • id (str) –

  • secret (str) –

  • auth_uri (str) –

  • token_uri (str) –

id: str#
secret: str#
auth_uri: str#
token_uri: str#
classmethod from_json_obj(obj)[source]#

Read an app from a JSON object, either from the Google Console JSON format or a set of kwargs

Parameters:

obj (dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]) –

Return type:

OAuth2App

classmethod from_json_file(path)[source]#

Read an app from a JSON file path

Parameters:

path (str) –

Return type:

OAuth2App

auth_url_with_pkce(redirect_uri, state, scopes)[source]#
Parameters:
  • redirect_uri (str) –

  • state (str) –

  • scopes (str) –

Return type:

tuple[str, str, str]

await refresh(client, user)[source]#
Parameters:
  • client (ClientSession) –

  • user (OAuth2User) –

await exchange_code(code, verifier, scopes, redirect_uri, client=None)[source]#
Parameters:
  • code (str) –

  • verifier (str) –

  • scopes (list[str]) –

  • redirect_uri (str) –

  • client (ClientSession | None) –

Return type:

OAuth2User

class SlyAPI.oauth2.OAuth2(app, user, on_refresh=None)[source]#

Bases: Auth

Provides the Auth interface implementation for OAuth2

Load an OAuth2 app and user from JSON files or existing objects.

Parameters:
app: OAuth2App#
user: OAuth2User#
await sign(client, request)[source]#
Parameters:
  • client (ClientSession) –

  • request (Request) –

Return type:

Request

await SlyAPI.oauth2.command_line_oauth2(app, redirect_host, redirect_port, usePin, scopes)[source]#
Parameters:
Return type:

OAuth2User