This commit is contained in:
phil 2025-01-03 13:36:22 +01:00
parent e1640b118d
commit e44d89e512

View file

@ -37,7 +37,7 @@
max-height: 3em
}
.user-info a.logout {
background-color: darkkhaki;
border: 2px solid darkkhaki;
padding: 3px 6px;
text-decoration: none;
text-align: center;
@ -49,6 +49,9 @@
.login-box {
text-align: center;
}
.login-box p {
margin: 0;
}
.login-toolbox {
max-width: 20em;
margin: auto;
@ -77,21 +80,34 @@
}
.debug-auth {
font-size: 90%;
background-color: #d8bebc75;
padding: 6px;
}
.debug-auth p, .debug .key {
.debug-auth * {
margin: 0;
}
.debug-auth p {
text-align: center;
border-bottom: 1px solid black;
}
.debug-auth ul {
padding: 0;
list-style: none;
}
.debug-auth p, .debug-auth .key {
font-weight: bold;
}
.content {
text-align: left;
}
.content .links-to-protected {
.content #links-to-check {
display: flex;
text-align: center;
}
.content .links-to-protected a {
.content #links-to-check a {
margin: 5px;
color: black;
padding: 3px 5px;
padding: 3px 6px;
text-decoration: none;
}
.hasResponseStatus {
@ -105,31 +121,29 @@
}
</style>
<script>
function setStatus(theUrl, theId) {
var xmlHttp = new XMLHttpRequest();
function checkHref(elem) {
var xmlHttp = new XMLHttpRequest()
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
var elem = document.getElementById(theId)
elem.classList.add("hasResponseStatus")
elem.classList.add("status-" + xmlHttp.status)
elem.title = "Response code " + xmlHttp.status
//console.log(theUrl, xmlHttp.status, elem)
elem.title = "Response code: " + xmlHttp.status
}
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
xmlHttp.open("GET", elem.href, true) // true for asynchronous
xmlHttp.send(null)
}
function checkPerms() {
setStatus("/protected", "protected")
setStatus("/protected-by-foorole", "protectedByfoorole")
setStatus("/protected-by-barrole", "protectedBybarrole")
function checkPerms(rootId) {
var rootElem = document.getElementById(rootId)
Array.from(rootElem.children).forEach(elem => checkHref(elem))
}
</script>
</head>
<body onload="checkPerms()">
<h1>Test app for OIDC</h1>
<body onload="checkPerms('links-to-check')">
<h1>FastAPI test app for OIDC</h1>
{% if not user %}
<div class="login-box">
<p>Not logged in</p>
<div class="login-toolbox">
{% for provider in settings.oidc.providers %}
<a href="login?provider={{ provider.name }}">Login with: {{ provider.name }}</a>
@ -150,20 +164,19 @@
</div>
{% endif %}
<div class="content">
<div class="links-to-protected">
<a id="protected" href="protected">
Access protected content
</a>
<a id="protectedByfoorole" href="protected-by-foorole">
Access + foorole protected content
</a>
<a id="protectedBybarrole" href="protected-by-barrole">
Access + barrole protected content
</a>
<p>
These links should get different response codes depending on the authorization:
</p>
<div id="links-to-check">
<a href="public">Public</a>
<a href="protected">Access protected content</a>
<a href="protected-by-foorole">Access + foorole protected content</a>
<a href="protected-by-barrole">Access + barrole protected content</a>
<a href="other">Other</a>
</div>
{% if user and settings.oidc.show_session_details %}
<div class="debug-auth">
<p>Session details:</p>
<p>Session details</p>
<ul>
{% for key, value in auth_data.items() %}
<li>