From 3e3db4246853dbab7cf93bf53866b3c3814f7fb8 Mon Sep 17 00:00:00 2001 From: phil Date: Thu, 2 Jan 2025 03:09:16 +0100 Subject: [PATCH] Cosmetic --- src/oidc-test/main.py | 8 ++++---- src/templates/index.html | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/oidc-test/main.py b/src/oidc-test/main.py index 8b02c25..58d7b50 100644 --- a/src/oidc-test/main.py +++ b/src/oidc-test/main.py @@ -5,7 +5,7 @@ from json import dumps from httpx import HTTPError from fastapi import Depends, FastAPI, HTTPException, Request, status -from fastapi.responses import HTMLResponse, RedirectResponse +from fastapi.responses import HTMLResponse, RedirectResponse, PlainTextResponse from fastapi.templating import Jinja2Templates from fastapi.security import ( OAuth2PasswordBearer, @@ -219,6 +219,6 @@ async def home( ) -@app.get("/private") -async def read_items(token: Annotated[str, Depends(get_current_user)]): - return {"token": token} +@app.get("/protected") +async def get_protected(user: Annotated[User, Depends(get_current_user)]): + return PlainTextResponse("Only authenticated users can see this") diff --git a/src/templates/index.html b/src/templates/index.html index 6e82edc..f13c4e7 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -68,12 +68,20 @@ .login-toolbox a:hover { background-color: lightgreen; } - .debug { + .login-toolbox .link-to-protected { + margin: 1em; + background-color: cyan; + box-shadow: 0px 0px 20px cyan; + } + .debug-auth { font-size: 90%; } - .debug p, .debug .key { + .debug-auth p, .debug .key { font-weight: bold; } + .content { + text-align: left; + } @@ -84,13 +92,15 @@ Logout {% else %} {% for provider in settings.oidc.providers %} - Login with: {{ provider.name }} + Login with: {{ provider.name }} {% else %} Cannot login: no oidc prodiver in settings.yaml {% endfor %} {% endif %} + + Ckeck here to get NOT_AUTHORIZED (401) or access protected content + - Private area, accessible only when Authorization is set (logged in)
{% if user %} @@ -103,7 +113,7 @@
{% endif %} {% if user and settings.oidc.show_session_details %} -
+

Session details:

    {% for key, value in auth_data.items() %} @@ -115,5 +125,7 @@
{% endif %} +
+