{"id":14989823,"url":"https://github.com/dorinclisu/fastapi-auth0","last_synced_at":"2025-04-10T06:18:54.084Z","repository":{"id":45492867,"uuid":"336768478","full_name":"dorinclisu/fastapi-auth0","owner":"dorinclisu","description":"FastAPI authentication and authorization using auth0.com","archived":false,"fork":false,"pushed_at":"2024-12-16T10:42:59.000Z","size":185,"stargazers_count":235,"open_issues_count":4,"forks_count":41,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T03:58:05.945Z","etag":null,"topics":["auth0","authentication","authorization","fastapi","permissions","python","scopes","swagger-ui","token"],"latest_commit_sha":null,"homepage":"","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/dorinclisu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-07T11:21:36.000Z","updated_at":"2025-03-31T05:12:25.000Z","dependencies_parsed_at":"2024-06-18T21:16:26.949Z","dependency_job_id":"f73d19d2-73db-43da-82e7-c86937f68c6d","html_url":"https://github.com/dorinclisu/fastapi-auth0","commit_stats":{"total_commits":74,"total_committers":7,"mean_commits":"10.571428571428571","dds":0.2432432432432432,"last_synced_commit":"4c8f34a5b4fbb6a9714fad67c5a2c15a57f422d2"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dorinclisu%2Ffastapi-auth0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dorinclisu%2Ffastapi-auth0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dorinclisu%2Ffastapi-auth0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dorinclisu%2Ffastapi-auth0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dorinclisu","download_url":"https://codeload.github.com/dorinclisu/fastapi-auth0/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166864,"owners_count":21058481,"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","authentication","authorization","fastapi","permissions","python","scopes","swagger-ui","token"],"created_at":"2024-09-24T14:18:58.540Z","updated_at":"2025-04-10T06:18:54.057Z","avatar_url":"https://github.com/dorinclisu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description\nIntegrate FastAPI with https://auth0.com in a simple and elegant way.\nGet automatic Swagger UI support for the implicit scheme (along others), which means that signing in using social providers is only a few clicks away with no additional code.\n\n# Installation\n- `pip install fastapi-auth0`\n\n# Requirements\nReading auth0 docs is recommended in order to understand the following concepts:\n - API's and audience\n - Applications\n - Grant types\n - Permissions and scopes\n\nThis library cannot do magic if the auth0 tenant is not configured correctly!\n\n### Email field requirements\nIn order to get email for Auth0User, the API must have \"openid profile email\" permission and the rule \"Add email to access token\" must be added with the matching namespace, see [tests](tests/README.md).\nThe security is not affected in any way if we don't do this, but we need to if we want to know the user email's address. Otherwise, email field will always be `None`.\n\n### Swagger UI login requirements\nIn order to utilize the interactive docs for the implicit flow, the callback url must be registered on the auth0 dashboard. For swagger this url is `{SWAGGER_DOCS_URL}/oauth2-redirect`, so if you are running FastAPI on localhost:8000, that becomes `http://localhost:8000/docs/oauth2-redirect`. Add it to \"Allowed Callback URLs\" for the application which you intend to login with (the client_id you input for Auth0ImplicitBearer authorization).\n\nIn order to logout and login with another user, it's necessary to manually call GET `https://{auth0_domain}/v2/logout`, becacause the Swagger UI logout button is not able to clear 3rd party session / cookies.\n\n# Example usage\n```Python\nfrom fastapi import FastAPI, Depends, Security\nfrom fastapi_auth0 import Auth0, Auth0User\n\nauth = Auth0(domain='your-tenant.auth0.com', api_audience='your-api-identifier', scopes={'read:blabla': ''})\napp = FastAPI()\n\n@app.get(\"/public\")\ndef get_public():\n    return {\"message\": \"Anonymous user\"}\n\n@app.get(\"/secure\", dependencies=[Depends(auth.implicit_scheme)])\ndef get_secure(user: Auth0User = Security(auth.get_user, scopes=['read:blabla'])):\n    return {\"message\": f\"{user}\"}\n```\n\n![](docs/swaggerui.jpg)\n\nExample user responses:\n```Python\nid='Art2l2uCeCQk5zDVbZzNZmQkLJXLd9Uy@clients' permissions=['read:blabla'] email=None               # user is M2M app\nid='auth0|5fe72b8eb2ac50006f725451' permissions=['read:blabla'] email='some.user@outlook.com'      # user signed up using auth0 database\nid='google-oauth2|115595596713285791346' permissions=['read:blabla'] email='other.user@gmail.com'  # user signed up using google\n```\n\n# Video tutorial\n[https://youtu.be/cGRdFjgAy9s](https://youtu.be/cGRdFjgAy9s)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdorinclisu%2Ffastapi-auth0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdorinclisu%2Ffastapi-auth0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdorinclisu%2Ffastapi-auth0/lists"}