sanic_jwt_extended.decorators module

sanic_jwt_extended.decorators.access_control(role=None, allow=None, deny=None)[source]
sanic_jwt_extended.decorators.fresh_jwt_required(function=None, allow=None, deny=None)[source]

A decorator to protect a Sanic endpoint. If you decorate an endpoint with this, it will ensure that the requester has a valid and fresh access token before allowing the endpoint to be called. See also: jwt_required()

sanic_jwt_extended.decorators.get_jwt_data(app: sanic.app.Sanic, token: str) → Dict[source]

Decodes encoded JWT token by using extension setting

Parameters:
  • app – A Sanic application
  • token – Encoded JWT string to decode
Returns:

Dictionary containing contents of the JWT

sanic_jwt_extended.decorators.get_jwt_data_in_request_header(app: sanic.app.Sanic, request: sanic.request.Request) → Dict[source]

Get JWT token data from request header with configuration. raise NoAuthorizationHeaderError when no jwt header. also raise InvalidHeaderError when malformed jwt header detected.

Parameters:
  • app – A Sanic application
  • request – Sanic request object that contains app
Returns:

Dictionary containing contents of the JWT

sanic_jwt_extended.decorators.jwt_optional(fn)[source]

A decorator to optionally protect a Sanic endpoint If an access token in present in the request, this will insert filled Token object to kwargs. If no access token is present in the request, this will insert Empty Token object to kwargs If there is an invalid access token in the request (expired, tampered with, etc), this will still call the appropriate error handler instead of allowing the endpoint to be called as if there is no access token in the request. and also does not check role

sanic_jwt_extended.decorators.jwt_refresh_token_required(fn)[source]

A decorator to protect a Sanic endpoint. If you decorate an endpoint with this, it will ensure that the requester has a valid refresh token before allowing the endpoint to be called.

sanic_jwt_extended.decorators.jwt_required(function=None, allow=None, deny=None)[source]

A decorator to protect a Sanic endpoint. If you decorate an endpoint with this, it will ensure that the requester has a valid access token before allowing the endpoint to be called. and if token check passed this will insert Token object to kwargs, This does not check the freshness of the access token. See also: fresh_jwt_required()

sanic_jwt_extended.decorators.verify_jwt_data_type(token_data: dict, token_type: str) → None[source]

Check jwt type with given argument. raise WrongTokenError if token type is not expected type,

Parameters:
  • token_data – Dictionary containing contents of the JWT
  • token_type – Token type that want to check (ex: access)