semvec/pypi-packages huggingface dataset:
fastapi-oidc-backend 0.6.0
Build resource servers with FastAPI
License: MIT
Requires Python: <4.0.0,>=3.11.2
Keywords: fastapi, authentication, oidc, openidconnect

# FastAPI Resource Backend

Build an OIDC resource server using FastAPI.

Your aplication receives the claims decoded from the access token.

Fork of fastapi-resource-server

# Usage

Run keycloak on port 8888:

```sh
docker container run --name auth-server -d -p 8080:8080 \
    -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin \
    quay.io/keycloak/keycloak:latest
```

Install dependencies

```sh
pip install fastapi fastapi_oidc_backend uvicorn
```

Create the main.py module

```python
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI, Security
from pydantic import BaseModel

from fastapi_oidc_backend.security import OidcResourceServer
from fastapi_oidc_backend.models import JwtKwargs

oidc_config = JwtKwargs(audience="myclient", issuer="http://localhost:8888/realms/myrealm")

@asynccontextmanager
async def app_startup(_app: FastAPI):
    await auth_scheme.load_configuration()
    yield

app = FastAPI(lifespan=app_startup,
              swagger_ui_init_oauth={
                  "clientId": oidc_config.audience,
                  "usePkceWithAuthorizationCodeGrant": True
              })
auth_scheme = OidcResourceServer(
    oidc_config,
    scheme_name="Keycloak",
)


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

```sh
uvicorn main:app
```
LiuML 0.1.1
LiuML(Li's Universal Misc Lib): Li-Yingping's personal python library for everything. Decicated to my girlfriend, LML.
License: MIT
Requires Python: >=3.12

# lml - Lemon's Misc Library

# Change Log

## 0.1.1

- Add command ``lml docker pull`` to pull a image as a .tar file locally without docker daemon.