Skip to main content

Flask middleware for Decode Auth

Project description

Decode Server Flask

A middleware for Flask for authenticating requests from Decode Auth Server.

Installing

Install using pip:

pip install decode_server_flask

A simple example

To integrate your Flask app with Decode Auth you only need to import the middleware and register it with the app. A simple example on how to do it:

from flask import Flask
from decode_server_flask import decode_server_flask
from os import environ

app = Flask(__name__)

# To setup the middleware, you need to get the Decode's RSA Public Key.
# You can read the key from an ENV variable.
decode_public_key = os.environ["DECODE_PUBLIC_KEY"]

# Or you can read the key from file.
public_key_file = open("decode-key.pub", "r")
decode_public_key = public_key_file.read()

# Then just pass the key to the middleware
app.wsgi_app = decode_server_flask(app.wsgi_app, decode_public_key)


# Now all the routes are protected!
# To call them you need a valid JWT which only the Decode Auth server can generate.
@app.route("/me", methods=["GET"])
def me_api():
    return {
        "user": "Paul Muad'Dib",
        "affiliation": "Fremen",
        "house": "Atreides",
    }

Developing

To install Decode Server Flask, alogn with the tools you need to develop and run tests, run the following in your virtualenv:

pip install -e .[dev]

Pushing updates

# First build the redistributable
python setup.py bdist_wheel sdist

# and then push it to pypi.org
twine upload dist/*

Project details


Download files

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

Source Distribution

decode_server_flask-1.0.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

decode_server_flask-1.0.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page