Skip to main content

FastAPI Auth OpenID Connect

Project description

FastAPI OIDC Security

This library allows your server-side application to check credentials with ease using OpenID Connect token flows. Use it with Firebase, Keycloak, Authentik or other OIDC providers.

Simple usage

You should provide OIDC configuration to the lib with one of the following ways:

  1. Environment variables

    OIDC_CONFIGURATION_URI=https://example.com/.well-known/openid-configuration
    
  2. Programmatically (use this method if you want several auth providers)

    Create python file with base configuration (e.g. auth.py):

    from fastapi_auth_oidc import OIDCAuthFactory
    
    OIDCAuth = OIDCAuthFactory(configuration_uri='https://example.com/.well-known/openid-configuration')
    

Then use factory in your handlers

from fastapi_auth_oidc import OIDCAuth  # if you use env vars
# from .auth import OIDCAuth  # if you use programmatically configured factory
from fastapi import FastAPI


app = FastAPI()

@app.get("/")
def read_root(user: Annotated[dict[str, Any], Depends(OIDCAuth())]):
    return user

Advanced configuration

You can customize various settings in your (default) factory and in each instance

Factory settings

Env name Factory arg name Default value Type Comment
OIDC_CONFIGURATION_URI configuration_uri - String (url) Fetched data will be named config further
OIDC_JWKS_URI jwks_uri config["jwks_uri"] String (url) Shoud be provided if no jwks_uri in configuration from configuration_uri
OIDC_USERINFO_URI userinfo_uri config["userinfo_uri"] String (url) URI to fetch user info in JWT or JSON format
OIDC_ISSUER issuer config["issuer"] String If no issuer provided, check will be skipped

Provider settings

Provider arg name Default value Type Comment
auto_error True Bool If no credentials or credentials wrong, UnauthenticatedException will be thrown
force_check False Bool Will check token on server for additional security, otherwise will check locally
fetch_userdata False Bool If fetch_userdata == True and userinfo_endpoint provided, will return data from userdata endpoint

Project details


Download files

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

Source Distribution

fastapi_auth_oidc-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_auth_oidc-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_auth_oidc-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_auth_oidc-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for fastapi_auth_oidc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b91ea098734a18f7e0db9dbf5a7af1632907b27bb9bbefa1a372e26375beb322
MD5 2bdd1da00eb3c91c2ef4b713d2672451
BLAKE2b-256 16cfe3e57e10190faf1404051d8cf0df49d2be24c95f9ad853cf6176d841d639

See more details on using hashes here.

File details

Details for the file fastapi_auth_oidc-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_auth_oidc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29977ee0b367bd70e7c96a20f3af0872f37cda21eb4b4f01ab92372d5261fc4b
MD5 6e836e67516dcf0d83a6c78fc3e32b49
BLAKE2b-256 9b2e0d4ebb1cc112d12b2dcda1bbe60e3216703c96f5bc0411e61d1154afed90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page