Hello,
How do i get user info of a user, generated by social login. For example ,
for a user, signed in by
import { Auth } from 'aws-amplify';
Auth.signUp({
username,
password,
attributes: {
email, // optional
phone_number, // optional - E.164 number convention
// other custom attributes
},
validationData: [] //optional
})
method, you can get the user info from the pool by,
Auth.currentAuthenticatedUser() once he signed in.
I have another set of users geneterated by federated login which is connected to the user pool.
by this method,
https://<your_user_pool_domain>/login?response_type=code&client_id=<your_client_id>&redirect_uri=https://www.example.com
Im using google to generate these users using their email id.
it creates users in the following name format in the pool. Google_105566480895441118673
How do i get the info's of these users with amplify or any other methods if its available.
As these users doesnt have any passwords assossicated. Only info's im getting while signin from cognito is an access_token, id_token, and expired at.
Helps would be appreciated
You need to go to Cognito User Pool console -> Federation -> Attributes mapping to map user attributes from Google to your Cognito User Pool
@powerful23 Sorry if my question was not clear. I have already done the mapping and i can see the details of the user in the GUI. My question is how to get the user info of those (Google users in the pool) programmatically.
For the users generated by amplify SDK i could get their details by Auth.currentAuthenticatedUser() method once he signed in.
I'm stuck on to get the details of Google users inside the pool(details from the pool).
Can you try:
async getCurrentUserAttributes() {
try {
const user = await Auth.currentAuthenticatedUser();
const attributes = await Auth.userAttributes(user);
console.log('get user attributes successfully', attributes);
} catch (e) {
console.log('get user attributes failed', e);
}
}
@powerful23
getCurrentUserAttributes() this method only works with pool users generated with amplify SDK.
The users added by Federated apps login, doesn't have a password so the above method will not return any result.
The federated users are added to the pool my this method,
https://<your_user_pool_domain>/login?response_type=code&client_id=<your_client_id>&redirect_uri=https://www.example.com
while login it returns an Access token, id_token.
I found this npm package https://www.npmjs.com/package/jwt-decode and decoded the idToken returned by coginto,
Which returned the needed info of the federated User from the pool.
Anyway, Thanks for your time and help. :)
@imewish can you say what should i do after Auth.federatedSignIn to save users into User Pool?
Thank you!
Most helpful comment
@powerful23
getCurrentUserAttributes()this method only works with pool users generated with amplify SDK.The users added by Federated apps login, doesn't have a password so the above method will not return any result.
The federated users are added to the pool my this method,
https://<your_user_pool_domain>/login?response_type=code&client_id=<your_client_id>&redirect_uri=https://www.example.comwhile login it returns an Access token, id_token.
I found this npm package https://www.npmjs.com/package/jwt-decode and decoded the idToken returned by coginto,
Which returned the needed info of the federated User from the pool.
Anyway, Thanks for your time and help. :)