Share via


Authorization Class

Class responsible for managing authorization flows.

Constructor

Authorization()

Parameters

Name Description
storage
Required
connection_manager
Required
auth_handlers
Default value: None
auto_signin
Default value: False
use_cache
Default value: False

Methods

__init__

Creates a new instance of Authorization.

Handlers defined in the configuration (passed in via kwargs) will be used only if auth_handlers is empty or None.

__new__
exchange_token

Exchanges or refreshes the token for a specific auth handler or the default handler.

get_token

Gets the token for a specific auth handler or the default handler.

The token is taken from cache, so this does not initiate nor continue a sign-in flow.

on_sign_in_failure

Sets a handler to be called when sign-in fails.

on_sign_in_success

Sets a handler to be called when sign-in is successfully completed.

sign_out

Attempts to sign out the user from a specified auth handler or the default handler.

__init__

Creates a new instance of Authorization.

Handlers defined in the configuration (passed in via kwargs) will be used only if auth_handlers is empty or None.

__init__(storage: Storage, connection_manager: Connections, auth_handlers: dict[str, AuthHandler] | None = None, auto_signin: bool = False, use_cache: bool = False, **kwargs)

Parameters

Name Description
storage
Required

The storage system to use for state management.

connection_manager
Required

The connection manager for OAuth providers.

auth_handlers
dict[str, AuthHandler], Optional

Configuration for OAuth providers.

Default value: None
auto_signin
Default value: False
use_cache
Default value: False

Exceptions

Type Description

When storage is None or no auth handlers provided.

__new__

__new__(**kwargs)

exchange_token

Exchanges or refreshes the token for a specific auth handler or the default handler.

async exchange_token(context: TurnContext, scopes: list[str] | None = None, auth_handler_id: str | None = None, exchange_connection: str | None = None) -> TokenResponse

Parameters

Name Description
context
Required

The context object for the current turn.

scopes

The scopes to request during the token exchange or refresh. Defaults to the list given in the AuthHandler configuration if None.

Default value: None
auth_handler_id

The ID of the auth handler to exchange or refresh the token for. If None, the default handler will be used.

Default value: None
exchange_connection

The name of the connection to use for token exchange. If None, the connection defined in the AuthHandler configuration will be used.

Default value: None

Returns

Type Description

The token response from the OAuth provider.

Exceptions

Type Description

If the specified auth handler ID is not recognized or not configured.

get_token

Gets the token for a specific auth handler or the default handler.

The token is taken from cache, so this does not initiate nor continue a sign-in flow.

async get_token(context: TurnContext, auth_handler_id: str | None = None) -> TokenResponse

Parameters

Name Description
context
Required

The context object for the current turn.

auth_handler_id
str

The ID of the auth handler to get the token for.

Default value: None

Returns

Type Description

The token response from the OAuth provider.

on_sign_in_failure

Sets a handler to be called when sign-in fails.

on_sign_in_failure(handler: Callable[[TurnContext, TurnState, str | None], Awaitable[None]]) -> None

Parameters

Name Description
handler
Required
Callable[[TurnContext, TurnState, Optional[str]], Awaitable[None]]

The handler function to call on sign-in failure.

Returns

Type Description

on_sign_in_success

Sets a handler to be called when sign-in is successfully completed.

on_sign_in_success(handler: Callable[[TurnContext, TurnState, str | None], Awaitable[None]]) -> None

Parameters

Name Description
handler
Required
Callable[[TurnContext, TurnState, Optional[str]], Awaitable[None]]

The handler function to call on successful sign-in.

Returns

Type Description

sign_out

Attempts to sign out the user from a specified auth handler or the default handler.

async sign_out(context: TurnContext, auth_handler_id: str | None = None) -> None

Parameters

Name Description
context
Required

The turn context for the current turn of conversation.

auth_handler_id

The ID of the auth handler to sign out from. If None, sign out from all handlers.

Default value: None

Returns

Type Description

None