Fix test client not using refresh endpoint properly

This commit is contained in:
Melon 2023-12-13 02:05:18 +00:00
parent 182c424b33
commit b4787f22aa
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
3 changed files with 119 additions and 112 deletions

View File

@ -5,11 +5,11 @@
<script> <script>
let loginData = { let loginData = {
target:{{.TargetOrigin}}, target:{{.TargetOrigin}},
userinfo:{{.TargetMessage}},
tokens: { tokens: {
access:{{.AccessToken}}, access:{{.AccessToken}},
refresh:{{.RefreshToken}}, refresh:{{.RefreshToken}},
}, },
userinfo:{{.TargetMessage}},
}; };
window.addEventListener("load", function () { window.addEventListener("load", function () {
window.opener.postMessage(loginData, loginData.target); window.opener.postMessage(loginData, loginData.target);

View File

@ -18,7 +18,7 @@ import (
"time" "time"
) )
func (h *HttpServer) refreshHandler(rw http.ResponseWriter, req *http.Request, params httprouter.Params) { func (h *HttpServer) refreshHandler(rw http.ResponseWriter, req *http.Request, _ httprouter.Params) {
ref := strings.TrimSuffix(req.Referer(), "/") ref := strings.TrimSuffix(req.Referer(), "/")
allowedClient, ok := (*h.services.Load())[ref] allowedClient, ok := (*h.services.Load())[ref]
if !ok { if !ok {

View File

@ -7,18 +7,20 @@
let currentTokens = null; let currentTokens = null;
const ssoService = "http://localhost:9090"; const ssoService = "http://localhost:9090";
window.addEventListener("message", function (event) { function updateTokenInfo(data) {
if (event.origin !== ssoService) return; currentTokens = data.tokens;
if (isObject(event.data)) { data.tokens = {
document.getElementById("someTextArea").textContent = JSON.stringify(event.data, null, 2); access: "*****",
refresh: "*****",
}
document.getElementById("someTextArea").textContent = JSON.stringify(data, null, 2);
let perms = document.getElementById("somePerms"); let perms = document.getElementById("somePerms");
while (perms.childNodes.length > 0) { while (perms.childNodes.length > 0) {
perms.childNodes.item(0).remove(); perms.childNodes.item(0).remove();
} }
currentTokens = event.data.tokens;
document.getElementById("tokenValues").textContent = JSON.stringify(currentTokens, null, 2); document.getElementById("tokenValues").textContent = JSON.stringify(currentTokens, null, 2);
let jwt = parseJwt(event.data.tokens.access); let jwt = parseJwt(currentTokens.access);
if (jwt.per != null) { if (jwt.per != null) {
jwt.per.forEach(function (x) { jwt.per.forEach(function (x) {
let a = document.createElement("li"); let a = document.createElement("li");
@ -26,6 +28,12 @@
perms.appendChild(a); perms.appendChild(a);
}); });
} }
}
window.addEventListener("message", function (event) {
if (event.origin !== ssoService) return;
if (isObject(event.data)) {
updateTokenInfo(event.data);
if (currentLoginPopup) currentLoginPopup.close(); if (currentLoginPopup) currentLoginPopup.close();
return; return;
@ -91,8 +99,7 @@
body: JSON.stringify({"token": currentTokens.refresh}), body: JSON.stringify({"token": currentTokens.refresh}),
}); });
let reqJson = await req.json(); let reqJson = await req.json();
currentTokens = reqJson; updateTokenInfo(reqJson);
document.getElementById("tokenValues").textContent = JSON.stringify(currentTokens, null, 2);
} }
</script> </script>
<style> <style>