Created
May 15, 2020 22:08
-
-
Save janakamarasena/fa7ce8d70d029d800de320705bba8593 to your computer and use it in GitHub Desktop.
account-linking.js
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 isLinkRequest = false; | |
| if (context.request.params.isLinkRequest !== null) { | |
| isLinkRequest = context.request.params.isLinkRequest[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") { | |
| var fedIdp = context.request.params.fedIdp[0]; | |
| 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