Created
May 16, 2020 23:51
-
-
Save janakamarasena/852440b5f4316e23f71df2752847b75f to your computer and use it in GitHub Desktop.
Blog - account linking scenario 1, basic association script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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