Oauth States¶
oauth_states
¶
OAuth state adapter interface.
Defines the abstract interface for OAuth state token storage. State tokens prevent CSRF attacks during OAuth authentication flows.
Classes¶
OAuthStateAdapter
¶
Bases: ABC
Abstract base class for OAuth state token operations.
State tokens prevent CSRF attacks in OAuth flows.
Functions¶
create
abstractmethod
¶
create(
*,
state_hash: str,
provider: str,
redirect_uri: str,
code_challenge: str | None = None,
code_challenge_method: str | None = None,
user_id: UUID | None = None,
expires_at: datetime
) -> Any
Create a new OAuth state token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_hash |
str
|
Hashed state token |
required |
provider |
str
|
OAuth provider name |
required |
redirect_uri |
str
|
Callback URL after OAuth |
required |
code_challenge |
str | None
|
Optional PKCE code challenge |
None
|
code_challenge_method |
str | None
|
PKCE challenge method (e.g., 'S256') |
None
|
user_id |
UUID | None
|
Optional user ID for linking existing account |
None
|
expires_at |
datetime
|
State token expiration datetime |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Created OAuth state object |
Source code in fastauth/adapters/base/oauth_states.py
get_valid
abstractmethod
¶
Get a valid (unused, non-expired) state token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_hash |
str
|
Hashed state token to look up |
required |
Returns:
| Type | Description |
|---|---|
Any
|
OAuth state record if found and not used, None otherwise |
Source code in fastauth/adapters/base/oauth_states.py
mark_used
abstractmethod
¶
Mark a state token as used (one-time use).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_hash |
str
|
Hashed state token to mark as used |
required |
cleanup_expired
abstractmethod
¶
Remove expired state tokens from database.
This can be called periodically to clean up old state tokens.