🔐 OAuth#

Client#

class OAuthClient(*, client_id, client_secret, base_url='https://exbo.net/oauth', redirect_uri='http://localhost', scope='', json=False)[source]#

Bases: APIClient

API Client for OAuth 2.0 authentication with EXBO services.

get_authorize_url(state=None, redirect_uri=None, scope=None)[source]#

Generate user authorization URL.

Parameters:
  • state (optional) – CSRF protection state string.

  • redirect_uri (optional) – Override default redirect URI.

  • scope (optional) – Override default scope.

Return type:

str

Returns:

URL for user authorization.

async get_app_token(scope=None)[source]#

Request application token using client credentials grant.

NOTE: New tokens replace and invalidate previous ones.

Parameters:

scope (optional) – Override default scope.

Return type:

AppToken

Returns:

Application token data.

async get_user_token(code)[source]#

Exchange authorization code for user token.

NOTE: New tokens replace and invalidate previous ones.

Parameters:

code (str) – Authorization code from user redirect.

Return type:

UserToken

Returns:

User token data with access and refresh token.

async refresh_user_token(refresh_token, scope=None)[source]#

Refresh expired user access token.

Parameters:
  • refresh_token (str) – Refresh token from previous authorization.

  • scope (optional) – Override default scope.

Return type:

UserToken

Returns:

Refreshed user token data.

async validate_user_token(token)[source]#

Validate user token and retrieve user information.

Parameters:

token (str) – User access token.

Return type:

UserInfo

Returns:

User account information.

Models#

class OAuthModel(**data)[source]#

Bases: BaseModel

Base model for OAuth response data.

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class TokenResponse(**data)[source]#

Bases: OAuthModel

Base token response.

token_type: str#
access_token: str#
expires_in: datetime#
classmethod parse_expires_in(expires_in)[source]#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class AppToken(**data)[source]#

Bases: TokenResponse

Application access token.

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class UserToken(**data)[source]#

Bases: TokenResponse

User access and refresh token.

refresh_token: str#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class UserInfo(**data)[source]#

Bases: OAuthModel

EXBO account information.

id: int#
uuid: UUID#
login: str#
display_login: Optional[str]#
distributor: str#
distributor_id: Optional[str]#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].