mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 15:44:07 +00:00
Fix test client not using refresh endpoint properly
This commit is contained in:
parent
182c424b33
commit
b4787f22aa
@ -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);
|
||||||
|
@ -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 {
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user