Skip to content

SimpleJWT class

esmerald_simple_jwt.config.SimpleJWT

Bases: JWTConfig

A subclass of JWTConfig.

When uwing this object, default values can be overridden to any application preference.

Example

from esmerald import Esmerald, EsmeraldAPISettings
from esmerald_simple_jwt.config import SimpleJWT


class AppSettings(EsmeraldAPISettings):
    simple_jwt: SimpleJWT = SimpleJWT(
        signing_key=settings.secret_key,
        backend_authentication=...,
        backend_refresh=...,
    )

backend_authentication instance-attribute

backend_authentication

The backend authentication being used by the system. A subclass of esmerald_simple_jwt.backends.BaseBackendAuthentication.

Warning

All backend authentication used by Esmerald Simple JWT must implement the async def authenticate() functionatility.

backend_refresh instance-attribute

backend_refresh

The backend refresh being used by the system. A subclass of esmerald_simple_jwt.backends.BaseRefreshAuthentication.

Warning

All backend authentication used by Esmerald Simple JWT must implement the async def refresh() functionatility.

login_model class-attribute instance-attribute

login_model = LoginEmailIn

A pydantic base model with the needed fields for the login. Usually email/username and `password.

This model can be found in esmerald_simple_jwt.schemas.LoginEmailIn and it is used by default for the login endpoint of a user into the system.

Tip

If you don't want to use the default email/password but instead something unique to you, you can simply create your own model and override the login_model settings from the SimpleJWT configuration.

refresh_model class-attribute instance-attribute

refresh_model = RefreshToken

A pydantic base model with the needed fields for the refresh token payload. Usually a dictionary of the format:

{
    "refresh_token": ...
}

This model can be found in esmerald_simple_jwt.schemas.RefreshToken and it is used by default for the refresh endpoint of an access_token in the system.

access_token_model class-attribute instance-attribute

access_token_model = AccessToken

Used for OpenAPI specification and return of the refresh token URL.

A pydantic base model with the representing the return of an access_token:

{
    "access_token": ...
}

This model can be found in esmerald_simple_jwt.schemas.AccessToken and it is used by default for the refresh endpoint return of an access_token in the system.

token_model class-attribute instance-attribute

token_model = TokenAccess

Used for OpenAPI specification only.

A pydantic base model with the representing the return of an access_token and refresh_token:

{
    "access_token": ...,
    "refresh_token": ...
}

This model can be found in esmerald_simple_jwt.schemas.TokenAccess and it is used by default for the refresh endpoint return of a dictionary containing the access and refresh tokens.

tags class-attribute instance-attribute

tags = None

OpenAPI tags to be displayed on each view provided by Esmerald Simple JWT.

These will be commmon to both views.

signin_url class-attribute instance-attribute

signin_url = '/signin'

The URL path in the format of /path used for the sign-in endpoint.

signin_summary class-attribute instance-attribute

signin_summary = 'Login API and returns a JWT Token.'

The OpenAPI URL summary for the path the sign-in endpoint.

signin_description class-attribute instance-attribute

signin_description = None

The OpenAPI URL description for the path the sign-in endpoint.

refresh_url class-attribute instance-attribute

refresh_url = '/refresh-access'

The URL path in the format of /path used for the refresh token endpoint.

refresh_summary class-attribute instance-attribute

refresh_summary = 'Refreshes the access token'

The OpenAPI URL summary for the path the refresh token endpoint.

refresh_description class-attribute instance-attribute

refresh_description = 'When a token expires, a new access token must be generated from the refresh token previously provided. The refresh token must be just that, a refresh and it should only return a new access token and nothing else\n    '

The OpenAPI URL description for the path the refresh token endpoint.

security class-attribute instance-attribute

security = [Bearer]

Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.

The Esmerald security is available to automatically used.

The security is applied to all the endpoints. ```