1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3519 from node-red/auto-login

Allow adminAuth to auto-login users when using passport strategy
This commit is contained in:
Nick O'Leary 2022-04-20 09:30:58 +01:00 committed by GitHub
commit 646a786b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions

View File

@ -106,9 +106,15 @@ async function login(req,res) {
urlPrefix += "/";
}
response = {
"type":"strategy",
"prompts":[{type:"button",label:mergedAdminAuth.strategy.label, url: urlPrefix + "auth/strategy"}]
"type":"strategy"
}
if (mergedAdminAuth.strategy.autoLogin) {
response.autoLogin = true
response.loginRedirect = urlPrefix + "auth/strategy"
}
response.prompts = [
{type:"button",label:mergedAdminAuth.strategy.label, url: urlPrefix + "auth/strategy"}
]
if (mergedAdminAuth.strategy.icon) {
response.prompts[0].icon = mergedAdminAuth.strategy.icon;
}

View File

@ -118,20 +118,26 @@ RED.user = (function() {
});
} else if (data.type == "strategy") {
var sessionMessage = /[?&]session_message=(.*?)(?:$|&)/.exec(window.location.search);
RED.sessionMessages = RED.sessionMessages || [];
if (sessionMessage) {
RED.sessionMessages.push(decodeURIComponent(sessionMessage[1]));
if (history.pushState) {
var newurl = window.location.protocol+"//"+window.location.host+window.location.pathname
window.history.replaceState({ path: newurl }, "", newurl);
} else {
window.location.search = "";
}
}
if (RED.sessionMessages.length === 0 && data.autoLogin) {
document.location = data.loginRedirect
return
}
i = 0;
for (;i<data.prompts.length;i++) {
var field = data.prompts[i];
var sessionMessage = /[?&]session_message=(.*?)(?:$|&)/.exec(window.location.search);
if (sessionMessage) {
RED.sessionMessages = RED.sessionMessages || [];
RED.sessionMessages.push(sessionMessage[1]);
if (history.pushState) {
var newurl = window.location.protocol+"//"+window.location.host+window.location.pathname
window.history.replaceState({ path: newurl }, "", newurl);
} else {
window.location.search = "";
}
}
if (RED.sessionMessages) {
var sessionMessages = $("<div/>",{class:"form-row",style:"text-align: center"}).appendTo("#node-dialog-login-fields");
RED.sessionMessages.forEach(function (msg) {