Flask-Rebar-Auth0 is a simple Flask-Rebar authenticator Auth0
Project description
Flask-Rebar-Auth0
Simple Flask-Rebar authenticator for Auth0. Your access tokens need to be JWT tokens for this authenticator to work.
Initialization
# Config
app.config.from_mapping({
"AUTH0_ENDPOINT": "perdu.auth0.com", # The Auth0 domain for your tenant
"AUTH0_ALGORITHMS": ["RS256"], # The authorized algorithms, you should not have to change it
"AUTH0_AUDIENCE": "https://api.perdu.com" # The API Identifier as set on Auth0
"AUTH0_HEADER_AUTHENTICATION": True # USe the authentication by header
"AUTH0_HEADER_NAME": "Authorization" # (OPTIONAL) Change the header used
"AUTH0_HEADER_PREFIX": "Bearer" # (OPTIONAL) Change the prefix used
# OR
"AUTH0_COOKIE_AUTHENTICATION": True # Use the authentication by cookie
"AUTH0_COOKIE_NAME": "Some Cookie" # Name of the cookie containing the access token
})
# Create
authenticator = Auth0Authenticator(app)
@authenticator.identity_handler
def create_user(claims: Dict[str, Any]) -> Any:
"""Built a user object from the claims"""
return { "id": claims["sub"] }
Usage
from flask_rebar_auth0 import get_authenticated_user
@registry.handles(
rule="/users/me",
method="GET",
marshal_schema=UserSchema(),
authenticator=authenticator, # Use the authenticator
)
def get_user():
return get_authenticated_user() # Get the user data created by the identity_handler
@registry.handles(
rule="/users/me/location",
method="GET",
marshal_schema=UserLocationSchema(),
authenticator=authenticator.with_scopes(["read:location"]), # Require some scopes to access the ressource
)
def get_user_location():
user = get_authenticated_user()
return locationService.get(user)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask_rebar_auth0-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f821435679ca2415ef9a59b8231ca023191727c14b550c016824fc45a1d44a2d |
|
MD5 | 216b524a4b5bcec9c3b23d989b867f65 |
|
BLAKE2b-256 | 495d2bda53bfcb521d0e8dd5023a2a0b74be10a0a35054dd9e2ea49fa9814d40 |