Simple JWT token flask service security library.
Project description
jwt_authenticator
jwt_authenticator is a simply python library for adding JWT token authentication/authorization in flask web sites/services. It controls access either by checking for just a validated token, or optionally, a single role claim from the token. Access is controlled by decorating the endpoint functions with an attribute.
Installation
Use the package manager pip to install jwt_authenticator.
pip install jwt-authenticator
If using RS256, you must also:
pip install cryptography
Usage
In the main application initialization area
from flask import Flask
from jwt_authenticator import AuthenticationHandler
APP = Flask(__name__)
AuthenticationHandler.load_configuration(APP)
In the endpoints
from jwt_authenticator import AuthenticationHandler, AuthError
@api.route('/<name>', methods=['GET'])
@AuthenticationHandler.requires_auth("admin")
def get_one(name):
return f"Hello {name}"
@api.route('/<name>', methods=['GET'])
@AuthenticationHandler.requires_auth()
def get_one(name):
return f"Hello {name}"
Configuration
jwt_authenticator requires two configuration values to work. These can be specified either in the normal Flask application configuration or as environment variables. Environment variable values will override application configuration values, when
AuthenticationHanlder.load_configuration(app)
is called.
APP.config (i.e. flask application configuration)
- SECRET - the key used to sign the JWT token. Option if JWKS_URL specified.
- AUDIENCE - the audience claim used in the JWT token
- JKWS_URL - [OPTIONAL] OIDC key discovery URL
- GROUPS_CLAIM - [OPTIONAL] which claim has the list of groups. Defaults to "groups"
Environment Variables
- JWT_SECRET - will override SECRET
- JWT_AUDIENCE - will override AUDIENCE
- JWKS_URL - will override JWKS_URL
- GROUPS_CLAIM - will override GROUPS_CLAIM
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Building
- Requires 'make'
make init
make test
make package
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jwt_authenticator-1.0.8.tar.gz
.
File metadata
- Download URL: jwt_authenticator-1.0.8.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92fc5716ddb9bad5cfe51dd136077fe45008b3ec88cae4738e2db55483a42525 |
|
MD5 | b21860e3c39eea39174e1f17bbb42a07 |
|
BLAKE2b-256 | cf7f58627b1cb481f8d111560c6a62155b6e04062e67b630b664cb1328736e95 |
File details
Details for the file jwt_authenticator-1.0.8-py3-none-any.whl
.
File metadata
- Download URL: jwt_authenticator-1.0.8-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f135de60b0016fa5b8630c59932f07f37d639cf1f0bd03d71c49d11fcc46c520 |
|
MD5 | 5e44eb15c5bb5f57764ea459860e6d51 |
|
BLAKE2b-256 | 6ae1bb20614e378fa0f55e306020afb95524431302f7fb997ce968a731b9ea4d |