Introspection
jwtlib.introspection
Auth client and access-control utilities.
Summary
This module provides pure authentication and authorization logic for validating JWTs via service-to-service introspection and resolving authenticated users.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 | |
Classes
Functions
authenticate_request
async
Authenticate an incoming request using token introspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
should_skip_authentication |
Callable[[str, str], bool]
|
Callable that decides whether authentication is required for a given HTTP method and path. |
required |
method |
str
|
HTTP method of the incoming request. |
required |
path |
str
|
Request path. |
required |
authorization_token |
str | None
|
JWT access token provided by the caller. |
required |
Returns:
| Type | Description |
|---|---|
Optional[PublicUser]
|
PublicUser | None: PublicUser if authentication succeeds; None if authentication is skipped. |
Raises:
| Type | Description |
|---|---|
InvalidToken
|
If authentication is required but the token is missing, invalid, or revoked. |
AuthServiceUnavailable
|
If the auth service cannot be reached. |
Notes
Responsibilities:
1 | |
Guarantees:
1 | |
introspect_token
async
Introspect a JWT using the external authentication service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
str
|
JWT access token to introspect. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the authenticated user's public payload. |
Raises:
| Type | Description |
|---|---|
InvalidToken
|
If the token is missing, invalid, inactive, or revoked. |
AuthServiceUnavailable
|
If the auth service cannot be reached or fails unexpectedly. |
Notes
Guarantees:
1 | |