Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document required usage of SessionMiddleware #8

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pip install keycloak-oauth[fastapi]

```python
from fastapi import FastAPI
from backend.settings import settings, BASE_URL # secrets
from starlette.middleware.sessions import SessionMiddleware
from backend.settings import settings, BASE_URL, SECRET_KEY # secrets
from keycloak.oauth import KeycloakOAuth2

keycloak = KeycloakOAuth2(
Expand All @@ -26,6 +27,7 @@ keycloak = KeycloakOAuth2(
keycloak.setup_fastapi_routes()

app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY)
app.include_router(keycloak.router, prefix="/auth")
```

Expand All @@ -42,8 +44,9 @@ pip install keycloak-oauth[starlette-admin]
```

```python
from starlette.middleware.sessions import SessionMiddleware
from starlette_admin.contrib.sqla import Admin
from backend.settings import settings, BASE_URL # secrets
from backend.settings import settings, BASE_URL, SECRET_KEY # secrets
from keycloak.oauth import KeycloakOAuth2
from keycloak.starlette_admin import KeycloakAuthProvider

Expand All @@ -60,6 +63,7 @@ admin = Admin(
title=...,
base_url=BASE_URL,
auth_provider=KeycloakAuthProvider(keycloak),
middlewares=[Middleware(SessionMiddleware, secret_key=SECRET_KEY)],
)
```

Expand Down
Loading