Models
jwtlib.models
Summary
jwtlib Models: Structured Data for Authentication.
This package defines the core data models used by jwtlib. These models are
categorized into request payloads, response objects, persistence documents,
and security context.
Model Categories
API Requests:
RegisterRequest: Payload for creating new user accounts.LoginRequest: User credentials for issuingJWTs.IntrospectRequest: Internal payload for service-to-service token verification.
API Responses:
PublicUser: A safe, non-sensitive projection of a user profile.LoginResponse: Contains the issued access token and thePublicUser.LogoutResponse: Instruction for clients to clear stateless session state.
Internal & Security:
User: The MongoDB-backed persistence model (Confined to repository layer).TokenPayload: Decoded claims from a validatedJWT(sub,exp).IntrospectResponse: Structured result of a token validity check.
Usage
Validating an Auth Request:
Projecting a User to Public View:
Public API
This package re-exports all validated data models required by the authentication system. Consumers should import from this namespace to ensure type safety and consistency.
LoginRequest/LoginResponseRegisterRequestLogoutResponsePublicUserIntrospectRequest/IntrospectResponseUser(Persistence)TokenPayload(JWT)
Classes
IntrospectRequest
Bases: BaseModel
Payload for requesting token introspection.
Attributes:
| Name | Type | Description |
|---|---|---|
token |
str
|
|
IntrospectResponse
Bases: BaseModel
Result of a token introspection operation.
Attributes:
| Name | Type | Description |
|---|---|---|
active |
bool
|
Indicates whether the token is valid and active. |
user |
Optional[PublicUser]
|
Public user details if the token is valid; otherwise null. |
LoginRequest
Bases: IdentityMixin, PasswordMixin
Payload for authenticating a user and issuing a JWT.
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
Username identifier. |
password |
str
|
Plain-text password to be verified. |
LoginResponse
Bases: BaseModel
Response returned after successful authentication.
Attributes:
| Name | Type | Description |
|---|---|---|
access_token |
str
|
|
user |
PublicUser
|
Public profile of the authenticated user. |
LogoutResponse
Bases: BaseModel
Response returned after a logout operation.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Human-readable logout confirmation. |
PublicUser
Bases: IdentityMixin, ActiveStateMixin
Public-facing user representation returned by authentication APIs.
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
Unique username identifier. |
email |
EmailStr
|
User's email address. |
is_active |
bool
|
Whether the user account is active. |
RegisterRequest
Bases: IdentityMixin, PasswordMixin
Payload for registering a new user account.
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
Unique username identifier. |
email |
EmailStr
|
User's email address. |
password |
str
|
Plain-text password (to be hashed by the repository layer). |
TokenPayload
Bases: BaseModel
Decoded JWT payload.
Attributes:
| Name | Type | Description |
|---|---|---|
sub |
str
|
Subject claim identifying the user (typically a username or user ID). |
exp |
int
|
Expiration time as a Unix timestamp (seconds since epoch). |
Notes
Responsibilities:
1 2 3 | |
Guarantees:
1 2 3 | |
User
Bases: BaseDocument, IdentityMixin, ActiveStateMixin
Internal user persistence model.
Attributes:
| Name | Type | Description |
|---|---|---|
hashed_password |
str
|
Secure hash of the user's password. |
Notes
Responsibilities:
1 2 3 | |
Guarantees:
1 2 3 | |