{"id":14974195,"url":"https://github.com/sytten/flask-rebar-auth0","last_synced_at":"2025-09-05T20:34:06.565Z","repository":{"id":34392503,"uuid":"178121779","full_name":"Sytten/flask-rebar-auth0","owner":"Sytten","description":"Flask-Rebar Authenticator for Auth0","archived":false,"fork":false,"pushed_at":"2023-01-13T01:25:19.000Z","size":29,"stargazers_count":13,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T10:50:47.522Z","etag":null,"topics":["auth0","flask","flask-rebar","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sytten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-28T03:47:08.000Z","updated_at":"2024-12-09T12:53:03.000Z","dependencies_parsed_at":"2023-01-15T06:46:47.487Z","dependency_job_id":null,"html_url":"https://github.com/Sytten/flask-rebar-auth0","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sytten%2Fflask-rebar-auth0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sytten%2Fflask-rebar-auth0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sytten%2Fflask-rebar-auth0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sytten%2Fflask-rebar-auth0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sytten","download_url":"https://codeload.github.com/Sytten/flask-rebar-auth0/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238455087,"owners_count":19475375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","flask","flask-rebar","python"],"created_at":"2024-09-24T13:50:08.406Z","updated_at":"2025-02-12T10:32:17.693Z","avatar_url":"https://github.com/Sytten.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-Rebar-Auth0\n[![PyPI version](https://badge.fury.io/py/flask-rebar-auth0.svg)](https://badge.fury.io/py/flask-rebar-auth0)\n[![Python versions](https://img.shields.io/pypi/pyversions/Flask-Rebar-Auth0.svg)](https://badge.fury.io/py/flask-rebar-auth0)\n[![Test](https://github.com/Sytten/flask-rebar-auth0/workflows/Test/badge.svg)](https://github.com/Sytten/flask-rebar-auth0)\n[![codecov](https://codecov.io/gh/Sytten/flask-rebar-auth0/branch/master/graph/badge.svg)](https://codecov.io/gh/Sytten/flask-rebar-auth0)\n[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Sytten/flask-rebar-auth0/blob/master/LICENSE)\n\nSimple [Flask-Rebar](https://github.com/plangrid/flask-rebar) authenticator for [Auth0](https://auth0.com).\nYour access tokens need to be [JWT tokens](https://auth0.com/docs/api-auth/tutorials/verify-access-token) for this authenticator to work.\n\n## Initialization\n```python\n# Config\napp.config.from_mapping({\n    \"AUTH0_ENDPOINT\": \"perdu.auth0.com\",      # The Auth0 domain for your tenant\n    \"AUTH0_ALGORITHMS\": [\"RS256\"],            # The authorized algorithms, you should not have to change it\n    \"AUTH0_AUDIENCE\": \"https://api.perdu.com\" # The API Identifier as set on Auth0\n\n    \"AUTH0_HEADER_AUTHENTICATION\": True       # Use the authentication by header\n    \"AUTH0_HEADER_NAME\": \"Authorization\"      # (OPTIONAL) Change the header used\n    \"AUTH0_HEADER_PREFIX\": \"Bearer\"           # (OPTIONAL) Change the prefix used\n    # OR\n    \"AUTH0_COOKIE_AUTHENTICATION\": True       # Use the authentication by cookie\n    \"AUTH0_COOKIE_NAME\": \"Some Cookie\"        # Name of the cookie containing the access token\n    \n    \"AUTH0_TESTING\": False                    # (OPTIONAL) Disable expiration check of tokens during tests   \n})\n\n# Create\nauthenticator = Auth0Authenticator(app)\n\n@authenticator.identity_handler\ndef create_user(claims: Dict[str, Any]) -\u003e Any:\n    \"\"\"Built a user object from the claims\"\"\"\n    return { \"id\": claims[\"sub\"] }\n```\n\n## Usage\n```python\nfrom flask_rebar_auth0 import get_authenticated_user\n\n\n@registry.handles(\n    rule=\"/users/me\",\n    method=\"GET\",\n    marshal_schema=UserSchema(),\n    authenticator=authenticator, # Use the authenticator\n)\ndef get_user():\n    return get_authenticated_user() # Get the user data created by the identity_handler\n\n\n@registry.handles(\n    rule=\"/users/me/location\",\n    method=\"GET\",\n    marshal_schema=UserLocationSchema(),\n    authenticator=authenticator.with_scopes([\"read:location\"]), # Require some scopes to access the ressource\n)\ndef get_user_location():\n    user = get_authenticated_user()\n    return locationService.get(user)\n```\n\n## Swagger\nIf you wish to use swagger, you will need to register the custom authenticators.\nThis is needed by `rebar` to be able to convert them to the right swagger [security definition](https://swagger.io/docs/specification/2-0/authentication/).\nIf 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.\n```python\nfrom flask_rebar_auth0 import register_authenticators\n\nregister_authenticators(registry)\n```\n\n## Testing\nDuring tests, we suggest setting `AUTH0_TESTING` to `True` to allow expired tokens to be used.\nThe setting also disables the request to auth0 for the keys, you MUST supply them manually.\n```python\nmy_key = {\n  \"alg\": \"RS256\",\n  \"kty\": \"RSA\",\n  \"use\": \"sig\",\n  \"x5c\": [\n    \"MIIC+TCCAeG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ar9K_MCE5bxIm8vJmm_H7NWfP1auTstf8dWXGN2hBlca3IghK4wbmtxBoD7iNnoFymGXg7H2jpvSnD1o1A9LXYhTYczxv6zNj4Cp9lmvXHBM1ofyY462l9xBPjMeP5xieuN-w3l3ujs_Z2SmaT4TTa2D-OroyyhhpMvmsMvVyUvVGfSiwuukUXHoS_zCsRRvbAJGAx4qVIAutzRiCaZLMnN5Nb10iB-iyQGLGT46a0L865urlH9u7qugXdVZs2Vfu1BLIs00sxlua9rUYyW81bCBMe-D6GxhqScM3o8N9XqZaI1LUQ9pf6P0Z0xrn2RQ\",\n  \"e\": \"AQAB\",\n  \"kid\": \"OTEyNDRCREE1OTlEOUYwNEM2QTM5RkJEODkxOEQyMDQ0NjYxRENEMw\",\n  \"x5t\": \"OTEyNDRCREE1OTlEOUYwNEM2QTM5RkJEODkxOEQyMDQ0NjYxRENEMw\"\n}\n\nauthenticator = Auth0Authenticator(app)\nauthenticator.add_key(my_key)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsytten%2Fflask-rebar-auth0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsytten%2Fflask-rebar-auth0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsytten%2Fflask-rebar-auth0/lists"}