rest_framework_simplejwt package
Submodules
rest_framework_simplejwt.authentication module
- class rest_framework_simplejwt.authentication.JWTAuthentication(*args, **kwargs)
Bases:
BaseAuthentication
An authentication plugin that authenticates requests through a JSON web token provided in a request header.
- authenticate(request: Request) Tuple[AuthUser, Token] | None
Authenticate the request and return a two-tuple of (user, token).
- authenticate_header(request: Request) str
Return a string to be used as the value of the WWW-Authenticate header in a 401 Unauthenticated response, or None if the authentication scheme should return 403 Permission Denied responses.
- get_header(request: Request) bytes
Extracts the header containing the JSON web token from the given request.
- get_raw_token(header: bytes) bytes | None
Extracts an unvalidated JSON web token from the given “Authorization” header value.
- get_user(validated_token: Token) AuthUser
Attempts to find and return a user using the given validated token.
- get_validated_token(raw_token: bytes) Token
Validates an encoded JSON web token and returns a validated token wrapper object.
- media_type = 'application/json'
- www_authenticate_realm = 'api'
- class rest_framework_simplejwt.authentication.JWTStatelessUserAuthentication(*args, **kwargs)
Bases:
JWTAuthentication
An authentication plugin that authenticates requests through a JSON web token provided in a request header without performing a database lookup to obtain a user instance.
- rest_framework_simplejwt.authentication.JWTTokenUserAuthentication
alias of
JWTStatelessUserAuthentication
rest_framework_simplejwt.models module
- class rest_framework_simplejwt.models.TokenUser(token: Token)
Bases:
object
A dummy user class modeled after django.contrib.auth.models.AnonymousUser. Used in conjunction with the JWTStatelessUserAuthentication backend to implement single sign-on functionality across services which share the same secret key. JWTStatelessUserAuthentication will return an instance of this class instead of a User model instance. Instances of this class act as stateless user objects which are backed by validated tokens.
- property groups: Group
- id
- is_active = True
- is_staff
- is_superuser
- pk
- property user_permissions: Permission
- username
rest_framework_simplejwt.serializers module
- class rest_framework_simplejwt.serializers.PasswordField(*args, **kwargs)
Bases:
CharField
- class rest_framework_simplejwt.serializers.TokenBlacklistSerializer(*args, **kwargs)
Bases:
Serializer
- token_class
alias of
RefreshToken
- class rest_framework_simplejwt.serializers.TokenObtainPairSerializer(*args, **kwargs)
Bases:
TokenObtainSerializer
- token_class
alias of
RefreshToken
- class rest_framework_simplejwt.serializers.TokenObtainSerializer(*args, **kwargs)
Bases:
Serializer
- default_error_messages = {'no_active_account': 'No active account found with the given credentials'}
- username_field = 'username'
- class rest_framework_simplejwt.serializers.TokenObtainSlidingSerializer(*args, **kwargs)
Bases:
TokenObtainSerializer
- token_class
alias of
SlidingToken
- class rest_framework_simplejwt.serializers.TokenRefreshSerializer(*args, **kwargs)
Bases:
Serializer
- token_class
alias of
RefreshToken
- class rest_framework_simplejwt.serializers.TokenRefreshSlidingSerializer(*args, **kwargs)
Bases:
Serializer
- token_class
alias of
SlidingToken
rest_framework_simplejwt.tokens module
- class rest_framework_simplejwt.tokens.AccessToken(token: Token | None = None, verify: bool = True)
Bases:
Token
- class rest_framework_simplejwt.tokens.BlacklistMixin
Bases:
object
If the rest_framework_simplejwt.token_blacklist app was configured to be used, tokens created from BlacklistMixin subclasses will insert themselves into an outstanding token list and also check for their membership in a token blacklist.
- blacklist() BlacklistedToken
Ensures this token is included in the outstanding token list and adds it to the blacklist.
- class rest_framework_simplejwt.tokens.RefreshToken(token: Token | None = None, verify: bool = True)
Bases:
BlacklistMixin
,Token
- property access_token: AccessToken
Returns an access token created from this refresh token. Copies all claims present in this refresh token to the new access token except those claims listed in the no_copy_claims attribute.
- access_token_class
alias of
AccessToken
- no_copy_claims = ('token_type', 'exp', 'jti', 'jti')
- class rest_framework_simplejwt.tokens.SlidingToken(*args, **kwargs)
Bases:
BlacklistMixin
,Token
- class rest_framework_simplejwt.tokens.Token(token: Token | None = None, verify: bool = True)
Bases:
object
A class which validates and wraps an existing JWT or can be used to build a new JWT.
- check_exp(claim: str = 'exp', current_time: datetime | None = None) None
Checks whether a timestamp value in the given claim has passed (since the given datetime value in current_time). Raises a TokenError with a user-facing error message if so.
- classmethod for_user(user: AuthUser) Token
Returns an authorization token for the given user that will be provided after authenticating the user’s credentials.
- get_token_backend() TokenBackend
- set_exp(claim: str = 'exp', from_time: datetime | None = None, lifetime: timedelta | None = None) None
Updates the expiration time of a token.
- set_iat(claim: str = 'iat', at_time: datetime | None = None) None
Updates the time at which the token was issued.
- set_jti() None
Populates the configured jti claim of a token with a string where there is a negligible probability that the same string will be chosen at a later time.
- property token_backend: TokenBackend
rest_framework_simplejwt.utils module
rest_framework_simplejwt.views module
- class rest_framework_simplejwt.views.TokenBlacklistView(**kwargs)
Bases:
TokenViewBase
Takes a token and blacklists it. Must be used with the rest_framework_simplejwt.token_blacklist app installed.
- class rest_framework_simplejwt.views.TokenObtainPairView(**kwargs)
Bases:
TokenViewBase
Takes a set of user credentials and returns an access and refresh JSON web token pair to prove the authentication of those credentials.
- class rest_framework_simplejwt.views.TokenObtainSlidingView(**kwargs)
Bases:
TokenViewBase
Takes a set of user credentials and returns a sliding JSON web token to prove the authentication of those credentials.
- class rest_framework_simplejwt.views.TokenRefreshSlidingView(**kwargs)
Bases:
TokenViewBase
Takes a sliding JSON web token and returns a new, refreshed version if the token’s refresh period has not expired.
- class rest_framework_simplejwt.views.TokenRefreshView(**kwargs)
Bases:
TokenViewBase
Takes a refresh type JSON web token and returns an access type JSON web token if the refresh token is valid.
- class rest_framework_simplejwt.views.TokenVerifyView(**kwargs)
Bases:
TokenViewBase
Takes a token and indicates if it is valid. This view provides no information about a token’s fitness for a particular use.
- class rest_framework_simplejwt.views.TokenViewBase(**kwargs)
Bases:
GenericAPIView
- authentication_classes = ()
- get_authenticate_header(request: Request) str
If a request is unauthenticated, determine the WWW-Authenticate header to use for 401 responses, if any.
- get_serializer_class() Serializer
If serializer_class is set, use it directly. Otherwise get the class from settings.
- permission_classes = ()
- post(request: Request, *args, **kwargs) Response
- serializer_class = None
- www_authenticate_realm = 'api'
- rest_framework_simplejwt.views.token_blacklist(request, *args, **kwargs)
Takes a token and blacklists it. Must be used with the rest_framework_simplejwt.token_blacklist app installed.
- rest_framework_simplejwt.views.token_obtain_pair(request, *args, **kwargs)
Takes a set of user credentials and returns an access and refresh JSON web token pair to prove the authentication of those credentials.
- rest_framework_simplejwt.views.token_obtain_sliding(request, *args, **kwargs)
Takes a set of user credentials and returns a sliding JSON web token to prove the authentication of those credentials.
- rest_framework_simplejwt.views.token_refresh(request, *args, **kwargs)
Takes a refresh type JSON web token and returns an access type JSON web token if the refresh token is valid.
- rest_framework_simplejwt.views.token_refresh_sliding(request, *args, **kwargs)
Takes a sliding JSON web token and returns a new, refreshed version if the token’s refresh period has not expired.
- rest_framework_simplejwt.views.token_verify(request, *args, **kwargs)
Takes a token and indicates if it is valid. This view provides no information about a token’s fitness for a particular use.