I am writing some server side login code for aws cognito and I want to verify the user who is logging in exists in the identity pool and to get the attributes assigned to them.
For email login I have this working well using the following code - using the aws-sdk:
let cognitoVerifyUser = null
try {
const cognitoIdProvider = new AWS.CognitoIdentityServiceProvider()
cognitoVerifyUser = await cognitoIdProvider.adminGetUser({
UserPoolId: pool.userPoolId,
Username: username,
}).promise()
} catch (e) {
throwError(e, e.message)
}
if (!cognitoVerifyUser) {
throwError(error.unauthorized, e)
}
const emailAttrib = cognitoVerifyUser.UserAttributes.find(a => a.Name == 'email')
if (!cognitoVerifyUser.Enabled || cognitoVerifyUser.UserStatus != 'CONFIRMED' || username != cognitoVerifyUser.Username || email != emailAttrib.Value) {
throwError(error.unauthorized, e)
}
But I am stuck trying to do something similar for federated users (login via google for example). Can someone help me out?