mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +00:00
Fix test client not using refresh endpoint properly
This commit is contained in:
parent
182c424b33
commit
b4787f22aa
@ -5,11 +5,11 @@
|
||||
<script>
|
||||
let loginData = {
|
||||
target:{{.TargetOrigin}},
|
||||
userinfo:{{.TargetMessage}},
|
||||
tokens: {
|
||||
access:{{.AccessToken}},
|
||||
refresh:{{.RefreshToken}},
|
||||
},
|
||||
userinfo:{{.TargetMessage}},
|
||||
};
|
||||
window.addEventListener("load", function () {
|
||||
window.opener.postMessage(loginData, loginData.target);
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"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(), "/")
|
||||
allowedClient, ok := (*h.services.Load())[ref]
|
||||
if !ok {
|
||||
|
@ -7,18 +7,20 @@
|
||||
let currentTokens = null;
|
||||
const ssoService = "http://localhost:9090";
|
||||
|
||||
window.addEventListener("message", function (event) {
|
||||
if (event.origin !== ssoService) return;
|
||||
if (isObject(event.data)) {
|
||||
document.getElementById("someTextArea").textContent = JSON.stringify(event.data, null, 2);
|
||||
function updateTokenInfo(data) {
|
||||
currentTokens = data.tokens;
|
||||
data.tokens = {
|
||||
access: "*****",
|
||||
refresh: "*****",
|
||||
}
|
||||
document.getElementById("someTextArea").textContent = JSON.stringify(data, null, 2);
|
||||
let perms = document.getElementById("somePerms");
|
||||
while (perms.childNodes.length > 0) {
|
||||
perms.childNodes.item(0).remove();
|
||||
}
|
||||
currentTokens = event.data.tokens;
|
||||
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) {
|
||||
jwt.per.forEach(function (x) {
|
||||
let a = document.createElement("li");
|
||||
@ -26,6 +28,12 @@
|
||||
perms.appendChild(a);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", function (event) {
|
||||
if (event.origin !== ssoService) return;
|
||||
if (isObject(event.data)) {
|
||||
updateTokenInfo(event.data);
|
||||
|
||||
if (currentLoginPopup) currentLoginPopup.close();
|
||||
return;
|
||||
@ -91,8 +99,7 @@
|
||||
body: JSON.stringify({"token": currentTokens.refresh}),
|
||||
});
|
||||
let reqJson = await req.json();
|
||||
currentTokens = reqJson;
|
||||
document.getElementById("tokenValues").textContent = JSON.stringify(currentTokens, null, 2);
|
||||
updateTokenInfo(reqJson);
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
Loading…
Reference in New Issue
Block a user