Skip to content

Commit

Permalink
Login callback: redirect to pulpito with session cookies
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari <[email protected]>
  • Loading branch information
VallariAg committed Aug 14, 2023
1 parent eccb49b commit d5e35e5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/routes/login.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
from fastapi import APIRouter, HTTPException, Request
from starlette.responses import RedirectResponse
from fastapi.responses import RedirectResponse
from dotenv import load_dotenv
import httpx

Expand All @@ -12,6 +12,7 @@
GH_AUTHORIZATION_BASE_URL = os.getenv("GH_AUTHORIZATION_BASE_URL")
GH_TOKEN_URL = os.getenv("GH_TOKEN_URL")
GH_FETCH_MEMBERSHIP_URL = os.getenv("GH_FETCH_MEMBERSHIP_URL")
PULPITO_URL = os.getenv("PULPITO_URL")

log = logging.getLogger(__name__)
router = APIRouter(
Expand Down Expand Up @@ -82,4 +83,7 @@ async def handle_callback(code: str, request: Request):
"access_token": token,
}
request.session["user"] = data
return RedirectResponse(url="/")
cookie = "; ".join([f'{str(key)}={str(value)}' for key, value in data.items()])
response = RedirectResponse(PULPITO_URL)
response.set_cookie(key="pulpitosession", value=cookie)
return response

0 comments on commit d5e35e5

Please sign in to comment.