common.application_layer.rest_api.jwtauth package
Submodules
common.application_layer.rest_api.jwtauth.jwtauth module
- class common.application_layer.rest_api.jwtauth.jwtauth.JWTAuth(private_key, public_key=None, algorithm='HS512', leeway=0, expiration=None, http_header='Authorization', auth_type='JWT', callback=None, audience='tta')
Bases:
objectThis is a pyramid authorization policy to handle JWT’s inspired heavily by https://github.com/wichert/pyramid_jwt/
- authenticated_userid(request: Request) int | None
returns the id of a Validated User :param request: the pyramid request :return: the users id, if validated
- create_token(user: User, **claims) str
creates a JWT from a User object with optional additional claims :param user: the User object to create the JWT for :param claims: additional claims to add to the JWT - will overwrite any existing ones from the User obj :return: a JWT string
- forget(request)
- get_claims(request: Request) dict
gets the jwt from the Authorization header and returns it’s claims :param request: the pyramid request :return: a dict of the claims
- identity(request: Request) User | None
validates a JWT and returns a User by the JWT user id (subject) claim value :param request: the pyramid request :return: a User object if valid, otherwise None
- permits(request: Request, context: object, permission: str) Allowed | Denied
this is the authorization function used for permission on any view or resource :param request: the Pyramid Request object :param context: the context of the calling view or resource :param permission: a string of the permission name for this context :return: a Pyramid Security Allowed or Denied object
- remember(request, principal, **kw)
Module contents
- common.application_layer.rest_api.jwtauth.create_jwt_security_policy(config, private_key=None, public_key=None, algorithm=None, expiration=None, leeway=None, http_header=None, auth_type=None, callback=None, audience=None)
This instantiates the JWTAuth class :param config: the Pyramid config object :param private_key: the private key used to encode/validate JWT’s :param public_key: a public key, if we go that way in the future :param algorithm: the encoding algorithm to use in the JWT’s :param expiration: how long from being issues should a JWT be good for - datetime.timedelta :param leeway: how many seconds of leeway we will allow for the JWT expiration :param http_header: the http header where we expect to find the JWT :param auth_type: the type of value in the above mention http_header :param callback: optional callback :param audience: the value to use in the JWT’s “aud” (audience) claim :return: a JWTAuth instance
- common.application_layer.rest_api.jwtauth.includeme(config)
- common.application_layer.rest_api.jwtauth.set_jwt_security_policy(config, private_key=None, public_key=None, algorithm=None, expiration=None, leeway=None, http_header=None, auth_type=None, callback=None, audience=None)