Skip to main content

Flask SDK for Axioms

Project description

axioms-flask-py PyPI

Axioms Python client for Flask. Secure your Flask APIs using Axioms Authentication and Authorization.

Prerequisite

  • Python 3.7+
  • An Axioms client which can obtain access token after user's authentication and authorization and include in Authorization header of all API request sent to Python/Flask application server.

Install SDK

Install axioms-flask-py in you Flask API project,

pip install axioms-flask-py

Basic usage

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. For a protected API view, is_authenticated should be always the first decorator. Order of decorators is important. has_required_scopes should always come after is_authenticated.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for axioms-flask-py, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size axioms_flask_py-0.0.2-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size axioms-flask-py-0.0.2.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page