All Projects → HarryMWinters → fastapi-oidc

HarryMWinters / fastapi-oidc

Licence: MIT License
Verify and decrypt 3rd party OIDC ID tokens to protect your fastapi (https://github.com/tiangolo/fastapi) endpoints.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to fastapi-oidc

fastapi-azure-auth
Easy and secure implementation of Azure AD for your FastAPI APIs 🔒 B2C, single- and multi-tenant support.
Stars: ✭ 174 (+625%)
Mutual labels:  oidc, fastapi
recommendation-api
Rank and serve recommendations
Stars: ✭ 14 (-41.67%)
Mutual labels:  fastapi
MLOps
MLOps template with examples for Data pipelines, ML workflow management, API development and Monitoring.
Stars: ✭ 28 (+16.67%)
Mutual labels:  fastapi
JJMumbleBot
A plugin-based All-In-One mumble bot solution in python 3.7+ with extensive features and support for custom plugins.
Stars: ✭ 40 (+66.67%)
Mutual labels:  fastapi
yarc
No description or website provided.
Stars: ✭ 109 (+354.17%)
Mutual labels:  fastapi
termpair
View and control terminals from your browser with end-to-end encryption 🔒
Stars: ✭ 1,390 (+5691.67%)
Mutual labels:  fastapi
fastapi-oidc-react
React + FastApi + Mongo - Login with Google and Azure (OIDC authorisation code flow)
Stars: ✭ 42 (+75%)
Mutual labels:  fastapi
fastapi-boilerplate
FastAPI boilerplate for real world production
Stars: ✭ 145 (+504.17%)
Mutual labels:  fastapi
fastapi-uvicorn-gunicorn-nginx-supervisor-boilerplate
Production ready boilerplate to start with Fastapi
Stars: ✭ 17 (-29.17%)
Mutual labels:  fastapi
fastapi-cache
fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.
Stars: ✭ 375 (+1462.5%)
Mutual labels:  fastapi
fastapi-mail
Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)
Stars: ✭ 321 (+1237.5%)
Mutual labels:  fastapi
Tplan
😃 T计划 是一个集成了任务队列、进程管理、爬虫部署、服务可视化监控、数据展示、在线编码、远程部署的通用系统。
Stars: ✭ 59 (+145.83%)
Mutual labels:  fastapi
wallpaper-api
An api which can use different sites to scrape images and serve them through API
Stars: ✭ 18 (-25%)
Mutual labels:  fastapi
serverless-mangum-examples
Example ASGI applications and Serverless Framework configurations using Mangum
Stars: ✭ 26 (+8.33%)
Mutual labels:  fastapi
brauzie
Awesome CLI for fetching JWT tokens for OAuth2.0 clients
Stars: ✭ 14 (-41.67%)
Mutual labels:  oidc
vue-element-admin-fastapi
vue-element-admin-fastapi
Stars: ✭ 145 (+504.17%)
Mutual labels:  fastapi
msgpack-asgi
Drop-in MessagePack support for ASGI applications and frameworks
Stars: ✭ 100 (+316.67%)
Mutual labels:  fastapi
Fast-API-and-Docker-BootCamp
This repository contains learning resources for Python Fast API Framework and Docker, Build High Performing Apps With Python BootCamp by Lux Academy and Data Science East Africa.
Stars: ✭ 24 (+0%)
Mutual labels:  fastapi
jsf
Creates fake JSON files from a JSON schema
Stars: ✭ 46 (+91.67%)
Mutual labels:  fastapi
OpenAM
OpenAM is an open access management solution that includes Authentication, SSO, Authorization, Federation, Entitlements and Web Services Security.
Stars: ✭ 476 (+1883.33%)
Mutual labels:  oidc

FastAPI OIDC

Test Documentation Status Package version


⚠️ See this issue for simple role-your-own example of checking OIDC tokens.

Verify and decrypt 3rd party OIDC ID tokens to protect your fastapi endpoints.

Documentation: ReadTheDocs

Source code: Github

Installation

pip install fastapi-oidc

Usage

Verify ID Tokens Issued by Third Party

This is great if you just want to use something like Okta or google to handle your auth. All you need to do is verify the token and then you can extract user ID info from it.

from fastapi import Depends
from fastapi import FastAPI

# Set up our OIDC
from fastapi_oidc import IDToken
from fastapi_oidc import get_auth

OIDC_config = {
    "client_id": "0oa1e3pv9opbyq2Gm4x7",
    # Audience can be omitted in which case the aud value defaults to client_id
    "audience": "https://yourapi.url.com/api",
    "base_authorization_server_uri": "https://dev-126594.okta.com",
    "issuer": "dev-126594.okta.com",
    "signature_cache_ttl": 3600,
}

authenticate_user: Callable = get_auth(**OIDC_config)

app = FastAPI()

@app.get("/protected")
def protected(id_token: IDToken = Depends(authenticate_user)):
    return {"Hello": "World", "user_email": id_token.email}

Using your own tokens

The IDToken class will accept any number of extra field but if you want to craft your own token class and validation that's accounted for too.

class CustomIDToken(fastapi_oidc.IDToken):
    custom_field: str
    custom_default: float = 3.14


authenticate_user: Callable = get_auth(**OIDC_config, token_type=CustomIDToken)

app = FastAPI()


@app.get("/protected")
def protected(id_token: CustomIDToken = Depends(authenticate_user)):
    return {"Hello": "World", "user_email": id_token.custom_default}
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].
OSZAR »