Skip to content

Commit

Permalink
Document required usage of SessionMiddleware (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Feb 27, 2024
1 parent f7aaf45 commit 2ca0641
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 2ca0641

Please sign in to comment.