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)
Swagger
If you wish to use swagger, you will need to register the custom authenticators.
This is needed by rebar to be able to convert them to the right swagger security definition.
If you use the Cookie authentication, please note that swagger 2.0 does support this method of authentication. It will be registered as a Cookie header.
from flask_rebar_auth0 import register_authenticators
register_authenticators(registry)
Metadata
Release files for flask-rebar-auth0 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask-rebar-auth0-0.1.5.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_rebar_auth0-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / flask-rebar-auth0-0.1.5.tar.gz
| Download URL | flask-rebar-auth0-0.1.5.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03b5c000455b213cf97a698a8d60d1a4ab31fba37d7fcdd99992d575d9c584d8
|
|
BLAKE2b-256 checksum How to use checksums |
67df2e8b9cc18e3e243f3a7cafd415941c99d332a56b27f5682aeea935bce3e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / flask_rebar_auth0-0.1.5-py3-none-any.whl
| Download URL | flask_rebar_auth0-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eed32ac26a26e35e47544b83a5b5bc1d05c879fcebdd19645b476d83d4bb1685
|
|
BLAKE2b-256 checksum How to use checksums |
74b54ca4a9aeedc1a660bc18e281d7c1cea06974ff9d3c568223077e57a05bce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|