Skip to main content

Build resource servers with FastAPI

Project description

FastAPI Resource Server

Build an OIDC resource server using FastAPI.

Your aplication receives the claims decoded from the access token.


Run keycloak on port 8888:

docker container run --name auth-server -d -p 8888:8080 \

Install dependencies

pip install fastapi fastapi_resource_server uvicorn

Create the module

from fastapi import Depends, FastAPI, Security
from pydantic import BaseModel

from fastapi_resource_server import JwtDecodeOptions, OidcResourceServer

app = FastAPI()

decode_options = JwtDecodeOptions(verify_aud=False)

auth_scheme = OidcResourceServer(

class User(BaseModel):
    username: str
    given_name: str
    family_name: str
    email: str

def get_current_user(claims: dict = Security(auth_scheme)):
    user = User.parse_obj(claims)
    return user

def read_current_user(current_user: User = Depends(get_current_user)):
    return current_user

Run the application

uvicorn main:app

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-resource-server-0.1.2.tar.gz (4.3 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page