All Projects → dorinclisu → fastapi-auth0

dorinclisu / fastapi-auth0

Licence: MIT license
FastAPI authentication and authorization using auth0.com

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to fastapi-auth0

restish
Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
Stars: ✭ 453 (+335.58%)
Mutual labels:  auth0, fastapi
feathers-casl
feathers.js + casl: hooks & channels
Stars: ✭ 25 (-75.96%)
Mutual labels:  permissions, authorization
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+10.58%)
Mutual labels:  permissions, authorization
spicedb
Open Source, Google Zanzibar-inspired fine-grained permissions database
Stars: ✭ 3,358 (+3128.85%)
Mutual labels:  permissions, authorization
ertis-auth
Generic token generator and validator service like auth
Stars: ✭ 28 (-73.08%)
Mutual labels:  auth0, authorization
token-cli
Command line utility for interacting with OAuth2 infrastructure to generate tokens
Stars: ✭ 19 (-81.73%)
Mutual labels:  authorization, token
spring-boot-jwt-auth
🔑 Sample Spring boot application secured using JWT auth in custom header(X-Auth-Token).
Stars: ✭ 57 (-45.19%)
Mutual labels:  authorization, swagger-ui
Appy
🚀 A full stack boilerplate web app
Stars: ✭ 225 (+116.35%)
Mutual labels:  permissions, authorization
mod authnz jwt
An authentication module for Apache httpd using JSON Web Tokens
Stars: ✭ 74 (-28.85%)
Mutual labels:  authorization, token
django-cancan
🔓Authorization library for Django
Stars: ✭ 36 (-65.38%)
Mutual labels:  permissions, authorization
Rbac
Hierarchical Role-Based Access Control for Node.js
Stars: ✭ 254 (+144.23%)
Mutual labels:  permissions, authorization
fastapi-cloudauth
Simple integration between FastAPI and cloud authentication services (AWS Cognito, Auth0, Firebase Authentication).
Stars: ✭ 221 (+112.5%)
Mutual labels:  auth0, fastapi
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+2556.73%)
Mutual labels:  permissions, authorization
graphql authorize
Authorization helpers for ruby-graphql fields
Stars: ✭ 23 (-77.88%)
Mutual labels:  permissions, authorization
Vue Router User Roles
A Vue.js plugin that protects routes based on user roles. Add your own authentication.
Stars: ✭ 237 (+127.88%)
Mutual labels:  permissions, authorization
rbac-tool
Rapid7 | insightCloudSec | Kubernetes RBAC Power Toys - Visualize, Analyze, Generate & Query
Stars: ✭ 546 (+425%)
Mutual labels:  permissions, authorization
Think Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in ThinkPHP 6.0 .
Stars: ✭ 155 (+49.04%)
Mutual labels:  permissions, authorization
Drf Access Policy
Declarative access policies/permissions modeled after AWS' IAM policies.
Stars: ✭ 200 (+92.31%)
Mutual labels:  permissions, authorization
hapi-doorkeeper
User authentication for web servers
Stars: ✭ 14 (-86.54%)
Mutual labels:  auth0, authorization
riam
AWS IAM inspired policy engine in Rust
Stars: ✭ 19 (-81.73%)
Mutual labels:  permissions, authorization

Description

Integrate FastAPI with https://auth0.com in a simple and elegant way. Get 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.

Installation

  • pip install fastapi-auth0

Requirements

Reading auth0 docs is recommended in order to understand the following concepts:

  • API's and audience
  • Applications
  • Grant types
  • Permissions and scopes

This library cannot do magic if the auth0 tenant is not configured correctly!

Email field requirements

In 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. The 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.

Swagger UI login requirements

In 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).

In 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.

Example usage

from fastapi import FastAPI, Depends, Security
from fastapi_auth0 import Auth0, Auth0User

auth = Auth0(domain='your-tenant.auth0.com', api_audience='your-api-identifier', scopes={'read:blabla': ''})
app = FastAPI()

@app.get("/public")
def get_public():
    return {"message": "Anonymous user"}

@app.get("/secure", dependencies=[Depends(auth.implicit_scheme)])
def get_secure(user: Auth0User = Security(auth.get_user, scopes=['read:blabla'])):
    return {"message": f"{user}"}

Example user responses:

id='Art2l2uCeCQk5zDVbZzNZmQkLJXLd9Uy@clients' permissions=['read:blabla'] email=None               # user is M2M app
id='auth0|5fe72b8eb2ac50006f725451' permissions=['read:blabla'] email='[email protected]'      # user signed up using auth0 database
id='google-oauth2|115595596713285791346' permissions=['read:blabla'] email='[email protected]'  # user signed up using google

Video tutorial

https://youtu.be/cGRdFjgAy9s

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].