Added cognito authentication - Fix 3
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -14,6 +14,7 @@
|
|||||||
"iptv",
|
"iptv",
|
||||||
"nohup",
|
"nohup",
|
||||||
"passlib",
|
"passlib",
|
||||||
|
"pyjwt",
|
||||||
"starlette",
|
"starlette",
|
||||||
"stefano",
|
"stefano",
|
||||||
"uvicorn",
|
"uvicorn",
|
||||||
|
|||||||
11
app/main.py
11
app/main.py
@@ -17,19 +17,18 @@ async def protected_route(user = Depends(get_current_user)):
|
|||||||
@app.get("/auth/callback")
|
@app.get("/auth/callback")
|
||||||
async def auth_callback(code: str):
|
async def auth_callback(code: str):
|
||||||
try:
|
try:
|
||||||
# Exchange the authorization code for tokens
|
|
||||||
tokens = exchange_code_for_token(code)
|
tokens = exchange_code_for_token(code)
|
||||||
|
|
||||||
# Create a response with the access token
|
# Use id_token instead of access_token
|
||||||
response = JSONResponse(content={
|
response = JSONResponse(content={
|
||||||
"message": "Authentication successful",
|
"message": "Authentication successful",
|
||||||
"access_token": tokens["access_token"]
|
"id_token": tokens["id_token"] # Changed from access_token
|
||||||
})
|
})
|
||||||
|
|
||||||
# Set the access token as a cookie
|
# Store id_token in cookie
|
||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
key="access_token",
|
key="token",
|
||||||
value=tokens["access_token"],
|
value=tokens["id_token"], # Changed from access_token
|
||||||
httponly=True,
|
httponly=True,
|
||||||
secure=True,
|
secure=True,
|
||||||
samesite="lax"
|
samesite="lax"
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ requests==2.31.0
|
|||||||
passlib[bcrypt]==1.7.4
|
passlib[bcrypt]==1.7.4
|
||||||
boto3==1.28.0
|
boto3==1.28.0
|
||||||
starlette>=0.27.0
|
starlette>=0.27.0
|
||||||
|
pyjwt==2.7.0
|
||||||
Reference in New Issue
Block a user