summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-11-02 22:13:07 +0100
committerAleš Smodiš <aless@guru.si>2015-11-02 22:13:07 +0100
commit0ed47f0499087770b26dc472c5b4d6a19d541318 (patch)
treee005bc12a297077c72e774b5f0f45495f51898fc
parent30a0c5bfe9af806f2153dac6f294241720b7731c (diff)
Add support for upgrade an existing account to the SAML-type account in the node web server.
-rw-r--r--web/main.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/web/main.js b/web/main.js
index 858408c..c0896b8 100644
--- a/web/main.js
+++ b/web/main.js
@@ -179,18 +179,29 @@ var guiHandlers = {
},
'saml_login': function samlLogin(session, message) {
- var samlData = null;
- performSamlAction('WaitLogin', {'sid': session.sid})
- .then(function (jsonObj) {
- if (jsonObj.code !== 0) return jsonObj;
- samlData = jsonObj.data;
- if (!samlData) return {'tid': message.tid, 'sid': message.sid, 'code': -2, 'message': 'IdP proxy did not return any SAML data'};
- if (!samlData.userData) return {'tid': message.tid, 'sid': message.sid, 'code': -3, 'message': 'IdP proxy did not return any SAML user data'};
- message.saml_data = samlData.userData; // add the data from SAML authentication, and forward everything to Python
- return sendDataToPython(message);
- })
- .then(function (jsonObj) {
- if (jsonObj.code === 0) session.samlData = samlData; // we need the SAML data to be able to perform global logout (saml_logout action)
+ var samlData = session.samlData,
+ p;
+ if (samlData && ('upgrade_account' in message)) {
+ message.saml_data = samlData.userData;
+ p = sendDataToPython(message);
+ }
+ else {
+ p = performSamlAction('WaitLogin', {'sid': session.sid})
+ .then(function (jsonObj) {
+ if (jsonObj.code !== 0) return jsonObj;
+ samlData = jsonObj.data;
+ if (!samlData) return {'tid': message.tid, 'sid': message.sid, 'code': -2, 'message': 'IdP proxy did not return any SAML data'};
+ if (!samlData.userData) return {'tid': message.tid, 'sid': message.sid, 'code': -3, 'message': 'IdP proxy did not return any SAML user data'};
+ message.saml_data = samlData.userData; // add the data from SAML authentication, and forward everything to Python
+ return sendDataToPython(message);
+ });
+ }
+
+ p.then(function (jsonObj) {
+ if ((jsonObj.code === 0) || (jsonObj.code === 1)) {
+ // we need the SAML data to be able to perform global logout (saml_logout action)
+ session.samlData = samlData;
+ }
session.send(jsonObj);
})
.catch(function (e) {
@@ -216,6 +227,8 @@ var guiHandlers = {
if (key !== 'userData') sd[key] = samlData[key];
}
+ delete session.samlData;
+
performSamlAction('WaitLogout', {'sid': session.sid, 'saml': JSON.stringify(sd)})
.then(function (jsonObj) {
if (jsonObj.code !== 0) return jsonObj;