Skip to content

Instantly share code, notes, and snippets.

View gessfred's full-sized avatar

Frédéric Gessler gessfred

View GitHub Profile
@gessfred
gessfred / fastapi-cors-and-jwt.py
Created September 25, 2022 14:07
Code sample to do JWT-based auth (Auth0) on cross-origin endpoints with FastAPI
from fastapi import FastAPI, Response, Request, Depends, Header, Cookie, HTTPException, status, WebSocket
from fastapi.responses import JSONResponse, PlainTextResponse
from jose import jwt
AUTH0_DOMAIN='xxxx.us.auth0.com'
ALGORITHMS = ["HS256", "RS256"]
API_AUDIENCE = 'https://api.example.com/'
def decode_auth_header(auth):
token = auth.split()