Skip to content

Instantly share code, notes, and snippets.

@janakamarasena
Last active May 17, 2020 17:00
Show Gist options
  • Select an option

  • Save janakamarasena/51ef0c96cd74d56068478b8b1e135553 to your computer and use it in GitHub Desktop.

Select an option

Save janakamarasena/51ef0c96cd74d56068478b8b1e135553 to your computer and use it in GitHub Desktop.
Blog - account linking scenario 2, association script.
var onLoginRequest = function onLoginRequest(context) {
var isLinkRequest = false;
if (context.request.params.isLinkRequest !== null) {
// Get the isLinkRequest param value from the request
isLinkRequest = context.request.params.isLinkRequest[0];
}
var fedIdp;
if (isLinkRequest == "true") {
// If it is an account linking request then
// get the federated Idp name
fedIdp = context.request.params.fedIdp[0];
}
var localUser;
executeStep(1,
{
onSuccess: function (context) {
// Get the local user
localUser = context.currentKnownSubject;
}
});
// Check whether this authentication request is to trigger
// the user linking flow
if (isLinkRequest == "true") {
executeStep(2,
{
authenticationOptions: [
{
// If there are multiple federated IDPs in step two we
// point to which IDP we need to do the association with
idp: fedIdp
}]
},
{
onSuccess: function (context) {
// Get the federated user
var fedUser = context.steps[2].subject;
// Link the federated user with the local user
doAssociationWithLocalUser(fedUser, localUser.username, localUser.tenantDomain, localUser.userStoreDomain);
// This is optional. If there are any claims comming from the federated user
// you can add them to the local user
localUser.localClaims["http://wso2.org/claims/gtalk"] = fedUser.remoteClaims.email;
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment