FastAPI Resource Server
Build an OIDC resource server using FastAPI.
Your aplication receives the claims decoded from the access token.
Usage
Run keycloak on port 8888:
docker container run --name auth-server -d -p 8888:8080 \
-e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin \
jboss/keycloak:latest
Install dependencies
pip install fastapi fastapi_resource_server uvicorn
Create the main.py 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(
"http://localhost:8888/auth/realms/master",
scheme_name="Keycloak",
jwt_decode_options=decode_options,
)
class User(BaseModel):
username: str
given_name: str
family_name: str
email: str
def get_current_user(claims: dict = Security(auth_scheme)):
claims.update(username=claims["preferred_username"])
user = User.parse_obj(claims)
return user
@app.get("/users/me")
def read_current_user(current_user: User = Depends(get_current_user)):
return current_user
Run the application
uvicorn main:app
Metadata
Release files for fastapi-resource-server 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastapi-resource-server-0.1.2.tar.gz | 4.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_resource_server-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / fastapi-resource-server-0.1.2.tar.gz
| Download URL | fastapi-resource-server-0.1.2.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bb4d122c74ae1dbde732bb03204af07243d6fb156c27f77f6c72c2c2e73c935
|
|
BLAKE2b-256 checksum How to use checksums |
fa3f1282232fdb685ffbda84a23dea2f21b173da75dbe0f0141142c262fb6590
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-53-generic
|
Release files / fastapi_resource_server-0.1.2-py3-none-any.whl
| Download URL | fastapi_resource_server-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
079195c4c9de35a1b265a6a433affbcb7cbfb44cf7ca6a5ab223c0f4f83bc3fb
|
|
BLAKE2b-256 checksum How to use checksums |
609376b2d698fa270ab4a220e666cf0c393d9daef66ec0ade859d409567f1860
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-53-generic
|
Security for fastapi-resource-server 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.