Skip to main content

Flask JWT Trivial

Pre-alpha, do not use! Use Flask JWT Extended instead.

About

Only bearer tokens are supported, no other methods.

The only valid algorithms for create_access_token() are HS256, HS384, or HS512. The default is HS256.

Installation

Install into a virtual environment:

virtualenv --python python3 venv
source venv/bin/activate
pip install flask-jwt-trivial

Example usage

First, generate a token and send it to the user. For them to access private routes, they must present that token as a bearer token, using the Authorization header, which will look something like this:

Authorization: Bearer <token-here>

Simple example follows. Note, it is up to you to manage the tokens, revoking them, checking expiry, etc.

from flask import Flask, jsonify, abort
from flask_jwt_trivial import Flask_JWT_Trivial


app = Flask(__name__)

# Don't actually put this in your source code.
# Maybe read it from an environment variable.
passphrase = "VERY-SECRET-PASSPHRASE"

# Initialise your Flask app like so:
flask_jwt_trivial = Flask_JWT_Trivial()
flask_jwt_trivial.init_app(
    app,
    passphrase=passphrase
)

@app.route("/private")
@flask_jwt_trivial.jwt_required
def private():
    return "Your token worked."

def authorised_to_receive_a_token():
    # Put your logic here, e.g. check the Flask
    # request and look up details in a database.
    if ok:
        return True
    else:
        return False

@app.route("/get_token")
def get_token():
    if not authorised_to_receive_a_token():
        abort(401) # Unauthorized

    token = flask_jwt_trivial.create_access_token()

    return jsonify(
        "data": {
            "type": "tokens",
            "attributes": {
                "token": token,
                "category": "Bearer",
            }
        }
    )

Options for flask_jwt_trivial.init_app() are:

  • app: Compulsory first arg, the Flask app.
  • algorithm: Optional. String. Algorithm used to encode/decode. Defaults to "HS256".
  • algorithms: Optional. List. Valid algorithms. Defaults to ["HS256","HS384","HS512"].
  • audience: Optional. String. JWT aud parameter.
  • issuer: Optional. String. JWT iss parameter, e.g. your organisation.
  • retfunc: Optional. A function that will be called on return. Useful if you want to capture the returned data and do something with it first.

Metadata

Release files for flask-jwt-trivial 0.0.3

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

Source distribution (sdist)

Source distribution for flask-jwt-trivial 0.0.3
File Size Uploaded Provenance Actions
flask_jwt_trivial-0.0.3.tar.gz 4.0 kB Without provenance Details for flask_jwt_trivial-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flask-jwt-trivial 0.0.3
File Interpreter ABI Platform Actions
flask_jwt_trivial-0.0.3-py3-none-any.whl Python 3 none any Details for flask_jwt_trivial-0.0.3-py3-none-any.whl

Total release size: 14.7 kB

Release files / flask_jwt_trivial-0.0.3.tar.gz

Download URL flask_jwt_trivial-0.0.3.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8fb98bc671f004ddb1ebecb98f10034ee2c440d100066c09916fa4cf502e4532
BLAKE2b-256 checksum
How to use checksums
190a056525261dddd8daafbcf51f68285844f7d08619bbd06201fe07e3f989cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / flask_jwt_trivial-0.0.3-py3-none-any.whl

Download URL flask_jwt_trivial-0.0.3-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b603acee8954a4361603e2bf9e339756252ada79ca9488626431b63e9004c74
BLAKE2b-256 checksum
How to use checksums
5ad8f4f73156f5bd28b88996ec22ffe943b4024612766421618221cc684954e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Security for flask-jwt-trivial 0.0.3

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.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

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