A simple library for parsing and verifying externally issued OIDC ID tokens in fastapi.
Project description
FastAPI OIDC
:warning: 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
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",
"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}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-oidc-0.0.5.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_oidc-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9199e40b0d15f92a0db671ba5e555306fc9383a75f24cc6ce2b51d6c07903d14 |
|
MD5 | a313e90c87be7f5fb45813a64b1c9518 |
|
BLAKE2b-256 | 339037887f01d18ea326cf1a3d307b0d25411dec0305a67e0a7739ffc200fd8a |