Metadata-Version: 2.1
Name: axioms-flask-py
Version: 0.0.1
Summary: Flask SDK for Axioms
Home-page: https://github.com/axioms-io/axioms-flask-py
Author: Axioms
Author-email: info@axioms.io
License: MIT
Project-URL: Documentation, https://github.com/axioms-io/axioms-flask-py
Project-URL: Source, https://github.com/axioms-io/axioms-flask-py
Project-URL: Tracker, https://github.com/axioms-io/axioms-flask-py/issues
Keywords: axioms authentication authorization iam authz authn jwt openid oauth2
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.7
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: pyjwt
Requires-Dist: jwcrypto
Requires-Dist: python-box
Requires-Dist: Flask
Requires-Dist: Flask-DotEnv
Requires-Dist: six

# 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!'})
```

