-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amazon Cognito Hosted UI - Merge users from different providers on registration #7149
Comments
Hi @Eisman111 –– this is possible today, just not through Amplify. I don't believe an Amplify abstraction of this feature is coming out of the woodworks soon, but here's how you can achieve what you'd like, today: Configure a Cognito User Pool post-confirmation Lambda trigger, which does the following:
const listUsersResponse = await cognitoIdentityServiceProvider.listUsers({
UserPoolId: event.userPoolId,
Filter: `email = "${event.request.userAttributes.email}"`,
}).promise();
const socialUser = listUsersResponse.Users.find((value) => value.UserStatus === 'EXTERNAL_PROVIDER');
// Make sure to decide on the right-hand of the `!==` –– I'd recommend looking only for `CONFIRMED`
const nativeUser = listUsersResponse.Users.find((value) => value.UserStatus !== 'EXTERNAL_PROVIDER');
await cognitoIdentityServiceProvider.adminLinkProviderForUser({
UserPoolId: event.userPoolId,
SourceUser: {
ProviderAttributeName: 'Cognito_Subject',
ProviderAttributeValue: providerUserId,
ProviderName: providerName,
},
DestinationUser: {
ProviderAttributeValue: nativeUser.Username,
ProviderName: 'Cognito',
},
}).promise(); & that sums it up! Please let me know if you encounter issues. If all goes smoothly, please close this issue out at your leisure. |
Hi @harrysolovay, thank you for the feedback! I tried with the adminLinkProviderForUser functionality but didn't put too much focus on it since I read from the documentation that only works when the external provider has not been created yet, but if you say I can use this I'll try again!
Furthermore, if I merge two users does it means they will only have one id right? Thank you for your time! |
I think these links are also related:
|
Nope, doesn't work. Linking a federated signed up user to a native congito user throws:
|
Closing this as a duplicate of #5104 so that we can consolidate efforts for tracking this feature-request |
Which Category is your question related to?
Authentication
What AWS Services are you utilizing?
Amazon Cognito Hosted UI
Is your feature request related to a problem? Please describe.
Our app use the Amazon Cognito Hosted UI configured to handle Authentication by email and social (facebook and google). When a user is registered with a social and then try to register with facebook or the native cognito user it will create a new user giving it a different token to connect to other aws services.
Describe the solution you'd like
I have seen the solution with the AdminLinkProviderForUser, the problem is that it doesn't work if the flow is inverted, it would good if we can use it in every possible scenario. Also, when the user log in he will mantain the same token so that for examples files in the S3 bucket would be still be accessible.
Describe alternatives you've considered
For now we will look into preventing user registrations with the same email address
Thanks,
Best regards
The text was updated successfully, but these errors were encountered: