Flask SDK for Axioms
Project description
axioms-flask-api
Axioms Python client for Flask. Secure your Flask APIs using Axioms Authentication and Authorization.
Install SDK
pip install axioms-flask-py
Basic usage
Add Config
Add .env
file
Create a .env
file and add following configs,
AXIOMS_DOMAIN=<your-axioms-slug>.axioms.io
AXIOMS_AUDIENCE=<your-axioms-resource-identifier>
Load Config
In your Flask app file (where flask app is declared) add following.
from flask_dotenv import DotEnv
env = DotEnv(app)
Register Error
In your Flask app file (where flask app is declared) add following.
from flask import jsonify
from axioms_flask.error import AxiomsError
@app.errorhandler(AxiomsError)
def handle_auth_error(ex):
response = jsonify(ex.error)
response.status_code = ex.status_code
return response
Guard API Views
Use is_authenticated
and has_required_scopes
decorators to guard your views.
has_required_scopes
requires an array of strings representing the required scopes as parameter.
For instance, to check openid
and profile
pass ['profile', 'openid']
as parameter in has_required_scopes
.
from axioms_flask.decorators import is_authenticated, has_required_scopes
@private_api.route('/private', methods=["GET"])
@is_authenticated
@has_required_scopes(['openid', 'profile'])
def api_private():
return jsonify({'message': 'All good. You are authenticated!'})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
axioms-flask-py-0.0.1.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for axioms_flask_py-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a63c9670d2b35abd0420912db46add6089e971fe0710f76c86a1aafa97aea921 |
|
MD5 | 05bad8a45e084c3f82700296cf4104e0 |
|
BLAKE2b-256 | df1cb701013aeadbb4d321dc5f783085e39f4fe26ff4e07804c22e1b189907b8 |