Utils
jwtlib.utils
Summary
Auth Utilities: Token validation and user resolution.
This module provides high-level helpers for validating JWT payloads and
resolving users, intended for use in dependency injection or middleware.
Classes
Functions
get_current_user
async
Validate token and return authenticated public user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
str
|
The |
required |
repo |
UserRepository
|
The user repository to use for resolution. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PublicUser |
PublicUser
|
The resolved and validated user object. |
Raises:
| Type | Description |
|---|---|
InvalidToken
|
If the token is missing, malformed, or invalid. |
UserNotFound
|
If the token is valid, but the user does not exist in the repository. |
get_user_repository
Return a singleton or new instance of the UserRepository.
Returns:
| Name | Type | Description |
|---|---|---|
UserRepository |
UserRepository
|
The user repository instance. |
get_validated_token_payload
Validate a JWT and return a typed payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
str
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TokenPayload |
TokenPayload
|
The validated and typed token payload. |
Raises:
| Type | Description |
|---|---|
JWTError
|
If the token is invalid or malformed. |