Link

JWT

class sanic_jwt.extended.JWT

A class to hold configs, create and revoke tokens.

All methods this class has is classmethod. It’s recommended to use without instanciate

def initialize

A classmethod to initialize class with context manager

Parmeters

  • app - A Sanic application

Return

  • ContextManager[JWT] - A context manager to setup extension

def create_access_token

A classmethod to create new access token

Parmeters

  • identity required - The identity of this token, which can be any data that is json serializable.
  • role - A string to specify role of access token for access control.
  • fresh - A boolean to mark token as fresh.
  • expires_delta - A datetime.timedelta to change time to expire. defaults to config’s access_token_expires. this parameter is positional-only
  • public_claims - Optional JSON serializable to add public claims to token. this parameter is positional-only
  • private_claims - Optional JSON serializable to add private claims to token. this parameter is positional-only
  • iss
  • aud
  • nbf

Return

  • str - An encoded access token

def create_refresh_token

A classmethod to create new refresh token

Parmeters

  • identity required - The identity of this token, which can be any data that is json serializable.
  • role - A string to specify role of access token for access control.
  • expires_delta - A datetime.timedelta to change time to expire. defaults to config’s access_token_expires. this parameter is positional-only
  • public_claims - Optional JSON serializable to add public claims to token. this parameter is positional-only
  • private_claims - Optional JSON serializable to add private claims to token. this parameter is positional-only
  • iss
  • aud
  • nbf

Return

  • str - An encoded refresh token

Signature of JWT

class JWT:
    config: Config = ...
    handler: Handler = ...
    blacklist: Optional[BlacklistABC] = ...

    @classmethod
    def initialize(cls: JWT, app: Sanic) -> ContextManager[JWT]: ...

    @classmethod
    def create_access_token(
        cls: JWT,
        identity: str,
        role: str = ...,
        fresh: bool = ...,
        *,
        expires_delta: datetime.timedelta = ...,
        public_claims: Dict[str, Any] = ...,
        private_claims: Dict[str, Any] = ...,
        iss: str = ...,
        aud: str = ...,
        nbf: datetime.datetime = ...,
    ) -> str: ...

    @classmethod
    def create_refresh_token(
        cls: JWT,
        identity: str,
        role: str = ...,
        *,
        expires_delta: datetime.timedelta = ...,
        public_claims: Dict[str, Any] = ...,
        private_claims: Dict[str, Any] = ...,
        iss: str = ...,
        aud: str = ...,
        nbf: datetime.datetime = ...,
    ) -> str: ...