Welcome to Flask-Auth0’s documentation!¶
Installation¶
Install Flask-Auth0 with pip
:
pip install flask-auth0
The development version can be downloaded from GitHub.
git clone https://github.com/sandtable/flask-auth0.git
cd flask-auth0
pip install -e .[dev,test]
Flask-Auth0 works with Python versions 2.7 and >= 3.4.
Quickstart¶
Here is a Hello World example.
You will need to set your Auth0 domain and Application Client ID and Secret.
from flask import Flask, jsonify
from flask_auth0 import Auth0
app = Flask(__name__)
app.secret_key = 'secret'
app.config['AUTH0_LOGOUT_URL'] = 'http://localhost:3000/logout'
app.config['AUTH0_CALLBACK_URL'] = 'http://localhost:3000/callback'
app.config['AUTH0_DOMAIN'] = '<your company>.eu.auth0.com'
app.config['AUTH0_CLIENT_ID'] = 'YOUR_AUTH0_CLIENT_ID'
app.config['AUTH0_CLIENT_SECRET'] = 'YOUR_AUTH0_CLIENT_SECRET'
auth0 = Auth0()
auth0.init_app(app)
@app.route('/')
@auth0.requires_auth
def hello():
return 'Hello world!'
@app.route('/logout')
@auth0.requires_auth
def logout():
auth0.logout()
return jsonify('logout')
if __name__ == '__main__':
app.run(port=3000)
Save this snippet as hello_world.py and add your required Auth0 configuration.
To run the example:
$ python hello_world.py
Then browse to http://localhost:3000 and sign in.
You can logout by navigating to: http://localhost:3000/logout
API¶
Flask-Auth0 is an extension for Flask that allows you to authenticate through Auth0 service.
-
class
flask_auth0.
Auth0
(app=None)¶ The core Auth0 client object.
-
access_token
¶ Get access token (user must be authenticated).
-
init_app
(app)¶ Do setup required by a Flask app.
-
jwt_payload
¶ Get JWT payload (user must be authenticated).
-
logout
()¶ Logout user.
Request the browser to clear the current session and also clear the Auth0 session (clearing the SSO cookie).
The user won’t be log out from a third party Identity Provider.
The user is redirected to the logout callback.
-
requires_auth
(view_func)¶ Decorates view functions that require a user to be logged in.
-