Skip to main content

Eve Auth JWT

https://img.shields.io/pypi/v/eve-auth-jwt.svg https://travis-ci.org/rs/eve-auth-jwt.svg?branch=master

An OAuth 2 JWT token validation module for Eve.

Installation

To install eve-auth-jwt, simply:

$ pip install eve-auth-jwt

At Eve initialization:

from eve import Eve
from eve_auth_jwt import JWTAuth

app = Eve(auth=JWTAuth, settings=SETTINGS)

Configuration

This module reads its configuration form Eve settings. Here is the list of new directives:

  • JWT_SECRET (required): Defines the symetric secret token secret used to de/encode the token (async keys support is a TODO).

  • JWT_ISSUER (required): Defines the required token issuer (iss claim).

  • JWT_AUDIENCES: Defines a list of accepted audiences (aud claim). If not provided, only tokens with no audience set will be accepted. The resource level audiences parameter is also available.

  • JWT_ROLES_CLAIM: Defines the claim name for roles. If set, Eve roles check will be activated, and any resources with allowed_roles set will require to have those roles present in the defined token’s claim.

  • JWT_SCOPE_CLAIM: Defines the claim name for scope. If set and the token has a claim of the same name containing the string viewer, only GET and HEAD methods will be granted. All other values are ignored and added to the list of exposed roles with the scope: prefix.

Reading Roles

If access is granted, the authentication module exposes roles and token’s claims thru get_authen_roles() and get_authen_claims() methods. You may access those values from your event hook as follow:

def my_hook(...)
    resource_def = app.config['DOMAIN'][resource_name]
    auth = resource_def['authentication']
    if 'somerole' in auth.get_authen_roles():
        # grant some finer access

Securing custom routes

JWT Authorization can be applied to any custom routes using the @requires_token wrapper. This annotation will only provide audience and role access control. User level access must be written manually.

Example of audience access control:

from eve_auth_jwt import requires_token, get_request_auth_value

@app.route('/my_resource/download', methods=['GET'])
@requires_token(audiences=['myAudience'])
def csv_download():
    # Allows all users with myAudience to access download
    account_id = get_request_auth_value()
    if check_user(account_id):

        abort(401)

    return generateCSV(account_id)

Example of myAdmin access control:

from eve_auth_jwt import requires_token

@app.route('/admin/my_resource/download', methods=['GET'])
@requires_token(audiences=['myAudience'], allowed_roles=['myAdmin'])
def csv_download():
    account_id = request.args.get('account_id', None)
    return generateCSV(account_id)

Access the parsed JWT token values

The parsed JWT token values are stored in the flask.g dict, but custom functions exist to aid in reading the values. The values are only available after the JWT token integrity check and user authorization occurs.

Example of access the parse JWT token fields:

from eve_auth_jwt import get_request_auth_value, get_authen_claims, get_authen_roles

def my_fn():
    # Request authentication value as a str
    account_id = get_request_auth_value()

    # JWT claims as a dict[str]
    payload = get_authen_claims()

    # Roles as arr[str]
    roles = get_authen_roles()

Licenses

All source code is licensed under the MIT License.

Metadata

Release files for eve-auth-jwt 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eve-auth-jwt 1.0.5
File Size Uploaded Provenance Actions
eve-auth-jwt-1.0.5.tar.gz 5.1 kB Without provenance Details for eve-auth-jwt-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eve-auth-jwt 1.0.5
File Interpreter ABI Platform Actions
eve_auth_jwt-1.0.5-py2.py3-none-any.whl Python 3, Python 2 none any Details for eve_auth_jwt-1.0.5-py2.py3-none-any.whl

Total release size: 13.3 kB

Release files / eve-auth-jwt-1.0.5.tar.gz

Download URL eve-auth-jwt-1.0.5.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e4a1823cccf9bd39f5dc60e347486e328291cc0804cd551aa50ae4a4715f04e3
BLAKE2b-256 checksum
How to use checksums
ed6d1d96fe6ae6a7a659d42c0576c664695ed5a1f17bae64c738a6bb612a20e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / eve_auth_jwt-1.0.5-py2.py3-none-any.whl

Download URL eve_auth_jwt-1.0.5-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a8b11fb7299b02022761d094f908b1a9c8d69c0d5dcecc7495c5045a5995a1e1
BLAKE2b-256 checksum
How to use checksums
ff0408f6740db62bd69c4b3d2fd37d7c1b723c3fa6f758e7d6b78ccbabb2442f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for eve-auth-jwt 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page