Skip to content

Instantly share code, notes, and snippets.

@janakamarasena
Created May 16, 2020 23:51
Show Gist options
  • Select an option

  • Save janakamarasena/852440b5f4316e23f71df2752847b75f to your computer and use it in GitHub Desktop.

Select an option

Save janakamarasena/852440b5f4316e23f71df2752847b75f to your computer and use it in GitHub Desktop.
Blog - account linking scenario 1, basic association script.
var onLoginRequest = function onLoginRequest(context) {
var fedUser;
executeStep(1,
{
onSuccess: function (context) {
var idpName = context.steps[1].idp;
// Only execute this flow when the user login from the google idp.
// If you want to target all your idps you can use something like
// idpName !== "LOCAL"
if (idpName === "google") {
fedUser = context.currentKnownSubject;
// Check is there is already a user association
var assocUser = getAssociatedLocalUser(fedUser);
if (assocUser == null) {
var claimMap = {};
claimMap["http://wso2.org/claims/emailaddress"] = fedUser.remoteClaims.email;
// getUniqueUserWithClaimValues(<claims to match the user>, <tenant domain>)
var storedLocalUser = getUniqueUserWithClaimValues(claimMap, "carbon.super");
if (storedLocalUser !== null) {
// Do the account linking
doAssociationWithLocalUser(fedUser, storedLocalUser.username, storedLocalUser.tenantDomain, storedLocalUser.userStoreDomain);
}
}
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment