show an error page when galtinn returns no access token
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30558eaa45
commit
2b5abc14d8
1 file changed
+11
-1
@@ -94,10 +94,20 @@ async def callback(request: Request, code: str, state: str):
|
|||||||
)
|
)
|
||||||
token_data = await r.json()
|
token_data = await r.json()
|
||||||
|
|
||||||
|
if not (access_token := token_data.get("access_token")):
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
"error.html",
|
||||||
|
{
|
||||||
|
"request": request,
|
||||||
|
"message": "Galtinn svarte uten autentiseringsnøkkel!",
|
||||||
|
},
|
||||||
|
status_code=502,
|
||||||
|
)
|
||||||
|
|
||||||
# Get user info from galtinn
|
# Get user info from galtinn
|
||||||
async with session.get(
|
async with session.get(
|
||||||
f"{GALTINN_API_URL}/oauth/userinfo/",
|
f"{GALTINN_API_URL}/oauth/userinfo/",
|
||||||
headers={"Authorization": f"Bearer {token_data['access_token']}"},
|
headers={"Authorization": f"Bearer {access_token}"},
|
||||||
) as r:
|
) as r:
|
||||||
if r.status != 200:
|
if r.status != 200:
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
|
|||||||
Reference in new issue
Block a user