working on authorization flow

This commit is contained in:
2024-07-23 15:56:16 +02:00
parent bb480b0b51
commit a277be5091
9 changed files with 58 additions and 23 deletions

View File

@@ -16,8 +16,6 @@ public class Forward extends PathHandler {
@Override
public boolean doGet(String path, HttpExchange ex) throws IOException {
System.out.printf("Forwarding (%d) %s to %s…\n", CODE, path, toPath);
ex.getResponseHeaders().add("Location", toPath);
ex.sendResponseHeaders(CODE, 0);
return true;
return sendRedirect(ex,toPath);
}
}

View File

@@ -5,8 +5,10 @@
<script src="common.js"></script>
<script src="user.js"></script>
<script src="authorization.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav></nav>
<h1>Authorization!</h1>
Not implemented, yet!
</body>

View File

@@ -1,11 +1,19 @@
var params = new URLSearchParams(window.location.search)
var json = Object.fromEntries(params);
async function handleResponse(response){
if (response.ok){
var json = await response.json();
console.log(json);
redirect(json.redirect_uri+'?code='+json.code+'&state='+json.state);
return;
}
}
fetch(api+"/authorize",{
method: 'POST',
body: JSON.stringify(json),
headers: {
'Content-Type': 'application/json'
}
})
}).then(handleResponse);

View File

@@ -1,7 +1,7 @@
var user = null;
async function handleUser(response){
if (response.status == UNAUTHORIZED) {
redirect('login.html?return_to='+encodeURI(window.location.href));
redirect('login.html?return_to='+encodeURIComponent(window.location.href));
return;
}
if (response.ok){