From c6fe00b2be33c722575a77159a174d60b1eb0a91 Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 27 Feb 2024 10:29:16 +0000 Subject: [PATCH 1/3] Document SessionMiddleware --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 94abbcc..3ab733a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ pip install keycloak-oauth[fastapi] ```python from fastapi import FastAPI +from starlette.middleware.sessions import SessionMiddleware from backend.settings import settings, BASE_URL # secrets from keycloak.oauth import KeycloakOAuth2 @@ -26,6 +27,7 @@ keycloak = KeycloakOAuth2( keycloak.setup_fastapi_routes() app = FastAPI() +app.add_middleware(SessionMiddleware, secret_key=settings.secret_key) app.include_router(keycloak.router, prefix="/auth") ``` From c31e8c5b8844c779713b30b8bbd0880b192bbb9d Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 27 Feb 2024 10:29:16 +0000 Subject: [PATCH 2/3] Document SessionMiddleware --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ab733a..2b12955 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ pip install keycloak-oauth[fastapi] ```python from fastapi import FastAPI from starlette.middleware.sessions import SessionMiddleware -from backend.settings import settings, BASE_URL # secrets +from backend.settings import settings, BASE_URL, SECRET_KEY # secrets from keycloak.oauth import KeycloakOAuth2 keycloak = KeycloakOAuth2( @@ -27,7 +27,7 @@ keycloak = KeycloakOAuth2( keycloak.setup_fastapi_routes() app = FastAPI() -app.add_middleware(SessionMiddleware, secret_key=settings.secret_key) +app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY) app.include_router(keycloak.router, prefix="/auth") ``` @@ -44,6 +44,7 @@ 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 keycloak.oauth import KeycloakOAuth2 @@ -62,6 +63,7 @@ admin = Admin( title=..., base_url=BASE_URL, auth_provider=KeycloakAuthProvider(keycloak), + middlewares=[Middleware(SessionMiddleware, secret_key=SECRET_KEY)], ) ``` From fdb1768d164690141a95d5dc81ed35697f13f8ab Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 27 Feb 2024 10:33:26 +0000 Subject: [PATCH 3/3] Add missing import --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b12955..1def57c 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ 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