Oauth Accounts¶
oauth_accounts
¶
OAuth account adapter interface.
Defines the abstract interface for OAuth account storage and management. Handles linking OAuth provider accounts to internal user accounts.
Classes¶
OAuthAccountAdapter
¶
Bases: ABC
Abstract base class for OAuth account database operations.
Implementations must provide database-specific logic for OAuth account management. The core business logic remains database-agnostic.
Functions¶
create
abstractmethod
¶
create(
*,
user_id: UUID,
provider: str,
provider_user_id: str,
access_token_hash: str,
refresh_token_hash: str | None = None,
expires_at: datetime | None = None,
email: str | None = None,
name: str | None = None,
avatar_url: str | None = None
) -> Any
Create a new OAuth account link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id |
UUID
|
Internal user ID |
required |
provider |
str
|
OAuth provider name (google, github, etc.) |
required |
provider_user_id |
str
|
User ID from OAuth provider |
required |
access_token_hash |
str
|
Hashed OAuth access token |
required |
refresh_token_hash |
str | None
|
Optional hashed OAuth refresh token |
None
|
expires_at |
datetime | None
|
Token expiration time |
None
|
email |
str | None
|
Email from provider (for reference) |
None
|
name |
str | None
|
Display name from provider |
None
|
avatar_url |
str | None
|
Profile picture URL |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Created OAuth account object |
Source code in fastauth/adapters/base/oauth_accounts.py
get_by_provider_user_id
abstractmethod
¶
Get OAuth account by provider and provider user ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider |
str
|
OAuth provider name |
required |
provider_user_id |
str
|
User ID from OAuth provider |
required |
Returns:
| Type | Description |
|---|---|
Any
|
OAuth account if found, None otherwise |
Source code in fastauth/adapters/base/oauth_accounts.py
get_by_user_id
abstractmethod
¶
Get OAuth accounts for a user, optionally filtered by provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id |
UUID
|
User's unique identifier |
required |
provider |
str | None
|
Optional provider name to filter by |
None
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of OAuth account objects |
Source code in fastauth/adapters/base/oauth_accounts.py
update_tokens
abstractmethod
¶
update_tokens(
*,
account_id: UUID,
access_token_hash: str,
refresh_token_hash: str | None = None,
expires_at: datetime | None = None
) -> None
Update OAuth tokens for an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id |
UUID
|
OAuth account ID |
required |
access_token_hash |
str
|
New hashed access token |
required |
refresh_token_hash |
str | None
|
New hashed refresh token (if applicable) |
None
|
expires_at |
datetime | None
|
New expiration time |
None
|
Source code in fastauth/adapters/base/oauth_accounts.py
delete
abstractmethod
¶
Remove OAuth account link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id |
UUID
|
OAuth account ID to delete |
required |