oidc-fastapi-test/src/templates/index.html

181 lines
4.7 KiB
HTML
Raw Normal View History

2025-01-02 02:14:30 +01:00
<html>
<head>
<title>FastAPI OIDC test</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: antiquewhite;
}
h1 {
text-align: center;
}
.content {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.user-info {
padding: 1em;
margin: 1em 0;
display: flex;
gap: 0.5em;
flex-direction: column;
width: fit-content;
align-items: center;
2025-01-03 12:39:41 +01:00
margin: 5px auto;
2025-01-02 02:14:30 +01:00
box-shadow: 0px 0px 10px lightgreen;
background-color: lightgreen;
}
.user-info * {
flex: 2 1 auto;
margin: 0;
}
.user-info .picture {
max-width: 3em;
max-height: 3em
}
2025-01-03 12:39:41 +01:00
.user-info a.logout {
background-color: darkkhaki;
padding: 3px 6px;
text-decoration: none;
text-align: center;
color: black;
}
.user-info a.logout:hover {
background-color: orange;
}
2025-01-02 02:14:30 +01:00
.login-box {
text-align: center;
}
.login-toolbox {
max-width: 20em;
margin: auto;
display: flex;
flex-direction: column;
padding: 0 1em;
gap: 5px;
}
.login-toolbox a {
background-color: lightblue;
padding: 3px 6px;
text-decoration: none;
text-align: center;
color: black;
flex: 1 1 auto;
}
.login-toolbox .error {
color: darkred;
padding: 3px 6px;
text-align: center;
font-weight: bold;
flex: 1 1 auto;
}
.login-toolbox a:hover {
background-color: lightgreen;
}
2025-01-02 03:09:16 +01:00
.debug-auth {
2025-01-02 02:14:30 +01:00
font-size: 90%;
}
2025-01-02 03:09:16 +01:00
.debug-auth p, .debug .key {
2025-01-02 02:14:30 +01:00
font-weight: bold;
}
2025-01-02 03:09:16 +01:00
.content {
text-align: left;
}
2025-01-03 12:39:41 +01:00
.content .links-to-protected {
display: flex;
text-align: center;
}
.content .links-to-protected a {
margin: 5px;
color: black;
padding: 3px 5px;
text-decoration: none;
}
.hasResponseStatus {
background-color: #88888840;
}
.hasResponseStatus.status-200 {
background-color: #00ff0040;
}
.hasResponseStatus.status-401 {
background-color: #ff000040;
}
2025-01-02 02:14:30 +01:00
</style>
2025-01-03 12:39:41 +01:00
<script>
function setStatus(theUrl, theId) {
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)
}
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
function checkPerms() {
setStatus("/protected", "protected")
setStatus("/protected-by-foorole", "protectedByfoorole")
setStatus("/protected-by-barrole", "protectedBybarrole")
}
</script>
2025-01-02 02:14:30 +01:00
</head>
2025-01-03 12:39:41 +01:00
<body onload="checkPerms()">
2025-01-02 02:14:30 +01:00
<h1>Test app for OIDC</h1>
2025-01-03 12:39:41 +01:00
{% if not user %}
2025-01-02 02:14:30 +01:00
<div class="login-box">
<div class="login-toolbox">
{% for provider in settings.oidc.providers %}
2025-01-02 03:09:16 +01:00
<a href="login?provider={{ provider.name }}">Login with: {{ provider.name }}</a>
2025-01-02 02:14:30 +01:00
{% else %}
<span class="error">Cannot login: no oidc prodiver in settings.yaml</span>
{% endfor %}
</div>
</div>
2025-01-03 12:39:41 +01:00
{% endif %}
2025-01-02 02:14:30 +01:00
{% if user %}
<div class="user-info">
2025-01-03 12:39:41 +01:00
<p>Hey, {{ user.name }}</p>
{% if user.picture %}
<img src="{{ user.picture }}" class="picture"></img>
{% endif %}
<p>{{ user.email }}</p>
<a href="logout" class="logout">Logout</a>
</div>
2025-01-02 02:14:30 +01:00
{% endif %}
2025-01-03 12:39:41 +01:00
<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>
</div>
2025-01-02 02:14:30 +01:00
{% if user and settings.oidc.show_session_details %}
2025-01-02 03:09:16 +01:00
<div class="debug-auth">
2025-01-02 02:14:30 +01:00
<p>Session details:</p>
<ul>
{% for key, value in auth_data.items() %}
<li>
<span class="key">{{ key }}</span>: {{ value }}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
2025-01-02 03:09:16 +01:00
<div class="content">
</div>
2025-01-02 02:14:30 +01:00
</body>
</html>