Added cognito authentication - Fix 12
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m10s
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m10s
This commit is contained in:
13
app/main.py
13
app/main.py
@@ -1,6 +1,6 @@
|
||||
from fastapi import FastAPI, Depends, HTTPException, Request
|
||||
from fastapi.responses import JSONResponse, RedirectResponse
|
||||
from app.cabletv.utils.auth import exchange_code_for_token, get_current_user, DOMAIN, CLIENT_ID
|
||||
from fastapi import FastAPI, Depends, HTTPException
|
||||
from fastapi.responses import RedirectResponse, JSONResponse
|
||||
from app.cabletv.utils.auth import get_current_user, exchange_code_for_token
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -15,16 +15,17 @@ async def protected_route(user = Depends(get_current_user)):
|
||||
return {"message": "Protected content", "user": user['Username']}
|
||||
|
||||
@app.get("/auth/callback")
|
||||
async def auth_callback(request: Request, code: str):
|
||||
async def auth_callback(code: str):
|
||||
try:
|
||||
redirect_uri = str(request.base_url) + "auth/callback"
|
||||
tokens = exchange_code_for_token(code, redirect_uri)
|
||||
tokens = exchange_code_for_token(code)
|
||||
|
||||
# Use id_token instead of access_token
|
||||
response = JSONResponse(content={
|
||||
"message": "Authentication successful",
|
||||
"id_token": tokens["id_token"] # Changed from access_token
|
||||
})
|
||||
|
||||
# Store id_token in cookie
|
||||
response.set_cookie(
|
||||
key="token",
|
||||
value=tokens["id_token"], # Changed from access_token
|
||||
|
||||
Reference in New Issue
Block a user