Skip to content

Service API

ServiceAuth(
    jwks_url: str,
    *,
    issuer: str = "authfort",
    algorithms: list[str] | None = None,
    jwks_cache_ttl: float = 3600.0,
    introspect_url: str | None = None,
    introspect_secret: str | None = None,
    introspect_cache_ttl: float = 0.0,
    cookie_name: str | None = None,
)
ServiceAuth(
    jwks_url: str,
    *,
    issuer: str = "authfort",
    algorithms: list[str] | None = None,
    jwks_cache_ttl: float = 3600.0,
    introspect_url: str | None = None,
    introspect_secret: str | None = None,
    introspect_cache_ttl: float = 0.0,
    cookie_name: str | None = None,
)

See Service Configuration for parameter details.


Verify a JWT using cached JWKS public keys.

ParamTypeDescription
tokenstrJWT access token

Returns: TokenPayload Raises: TokenVerificationError

Check token validity via the auth server’s introspection endpoint.

ParamTypeDescription
tokenstrJWT access token

Returns: IntrospectionResult


Dependency that extracts and verifies the user from the request.

Returns: TokenPayload Raises: HTTPException(401) if not authenticated

Dependency factory that checks for a required role.

ParamTypeDescription
rolestr | list[str]Required role(s)

Returns: dependency that returns TokenPayload Raises: HTTPException(403) if role missing


Frozen dataclass with verified token claims.

FieldTypeDescription
substrUser ID
emailstrUser email
namestr | NoneDisplay name
roleslist[str]User roles
token_versionintToken version
expintExpiration timestamp
iatintIssued-at timestamp
issstrIssuer

Frozen dataclass with introspection response.

FieldTypeDescription
activeboolWhether the token is currently valid
substr | NoneUser ID
emailstr | NoneUser email
namestr | NoneDisplay name
roleslist[str] | NoneCurrent roles (from database)
token_versionint | NoneCurrent token version
expint | NoneExpiration timestamp
iatint | NoneIssued-at timestamp
issstr | NoneIssuer

Exception raised when token verification fails.

FieldTypeDescription
messagestrError message
codestrError code (token_expired, invalid_token, invalid_issuer, key_not_found)