I have had SSO integration from my site for a few years now with no issue.
Recently users started saying that when they login it redirects to my site to login and then ends back up at Discourse still showing they need to Login. I having been trying to debug but I am not seeing any issues. It just seems like at the end when it does the redirect to Login something is going wrong.
When I look in Discourse the user account is created, but for some reason it is not logging them in.
Here is a quick video showing what I am seeingâŚ
I followed this info:
âŚand am using the latest discourse-sso javascript library.
This is my AWS Lambda which is fronted by an API GatewayâŚ
'use strict';
exports.handler = (event, context, callback) => {
console.log(event);
var discourse_sso = require('discourse-sso');
var sso = new discourse_sso("********************"); // secret hidden
var body = JSON.parse(event.body);
var payload = body.sso; // fetch from incoming request
var sig = body.sig; // fetch from incoming request
if(sso.validate(payload, sig)) {
var nonce = sso.getNonce(payload);
var userparams = {
// Required, will throw exception otherwise
"nonce": nonce,
"external_id": body.externalId,
"email": body.email,
// Optional
"username": body.username,
"name": body.name
};
console.log("User: " + JSON.stringify(userparams));
var q = sso.buildLoginString(userparams);
console.log("q: " + q);
// Redirect
var response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({"q":q})
};
callback(null, response);
} else {
// What to do if doesn't validate?
var responseError = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({"error":"SSO Validation Error"})
};
callback(null, responseError);
}
};
When the Login button is clicked from Discourse it calls my web app where the user is validated and then if validation passes calls the followingâŚ
if (state.get(["appState", "urlParams", "sso"]) && state.get(["appState", "urlParams", "sig"])) {
var userMetadata = getUserMetadata(result);
var body = {
sso: state.get(["appState", "urlParams", "sso"]),
sig: state.get(["appState", "urlParams", "sig"]),
externalId: keyPrefix,
email: userMetadata.email,
name: userMetadata.name,
username: username
};
request
.post('https://**********.execute-api.us-east-1.amazonaws.com/prod/discourse-sso')
.send(body)
.end(function (err, res) {
if (err || !res.ok) {
alert(err.message);
} else {
window.location.replace("https://forum.miralouaero.com/session/sso_login?" + res.body.q);
}
});
}
Any help understanding what may be going on would be appreciated.