Buckets:

download
raw
2.25 kB
from collections.abc import Awaitable, Callable
from typing import Any
from fastapi_fullauth.adapters.base import AbstractUserAdapter
from fastapi_fullauth.core.crypto import hash_refresh_token
from fastapi_fullauth.core.tokens import TokenEngine
from fastapi_fullauth.types import RefreshToken, TokenPair, UserSchema
# Async callback that builds the custom claims for a user's tokens; flows call
# it only after authentication succeeds (e.g. FullAuth.get_custom_claims).
ClaimsProvider = Callable[[UserSchema], Awaitable[dict[str, Any]]]
async def issue_token_pair(
adapter: AbstractUserAdapter,
token_engine: TokenEngine,
user: UserSchema,
*,
extra_claims: dict[str, Any] | None = None,
family_id: str | None = None,
roles: list[str] | None = None,
user_agent: str | None = None,
ip_address: str | None = None,
) -> TokenPair:
"""Create an access/refresh token pair for ``user`` and persist the refresh token.
Shared by the login, OAuth, passkey, and refresh-rotation flows. Pass
``family_id`` to keep an existing refresh-token family (rotation); omit it
to start a new one. Pass ``roles`` to reuse an already-fetched list and skip
the lookup. ``user_agent``/``ip_address`` are recorded on the refresh token
so the session list can show the device and origin of each sign-in.
"""
if roles is None:
roles = await adapter.get_user_roles(user.id)
access, refresh_meta = token_engine.create_token_pair(
user_id=str(user.id),
roles=roles,
extra=extra_claims,
family_id=family_id,
)
# Only the sha256 digest is persisted: a leaked database must not hand out
# live sessions. Lookups hash the presented token the same way.
await adapter.store_refresh_token(
RefreshToken(
token=hash_refresh_token(refresh_meta.token),
user_id=user.id,
expires_at=refresh_meta.expires_at,
family_id=refresh_meta.family_id,
user_agent=user_agent,
ip_address=ip_address,
)
)
return TokenPair(
access_token=access,
refresh_token=refresh_meta.token,
expires_in=token_engine.config.ACCESS_TOKEN_EXPIRE_MINUTES * 60,
)

Xet Storage Details

Size:
2.25 kB
·
Xet hash:
e3fcaf38dbd72ed05e03bef76e11ece7bfecccec2e0d1f1ceee4d395eb055359

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.