amazon-cognito-identity-dart-2
amazon-cognito-identity-dart-2 copied to clipboard
How to proceed after getting Open ID credentials (e.g. Google Sign In)?
I'm trying to use Google Sign In through Open Id Connect provider together with Cognito. I'm able to get the CognitoCredentials
more or less like this:
final aToken = CognitoAccessToken(accessToken); // from Google Sign In
final iToken = CognitoIdToken(idToken); // from Google Sign
final _credential = CognitoCredentials(
'us-east-1:axxx',
_userPool,
);
await _credential.getAwsCredentials(
idToken,
'accounts.google.com',
);
At this stage credentials object contains all the fields.
However, I'm not sure how to create and authenticate the CognitoUser
having this data. When calling
final session = CognitoUserSession(
iToken,
aToken,
// refreshToken: rToken, // no access to refresh token from google sign in
);
final user = CognitoUser(
'xxx',
_userPool,
signInUserSession: session,
);
final attributes = await user.getUserAttributes();
The last call fails with User is not authenticated
exception.
Is there something obvious I'm missing? How to get the authenticated CognitoUser
?
I hope official documentation will help you https://docs.aws.amazon.com/cognito/latest/developerguide/google.html
I'm not sure if I follow but based on the docs you linked it looks like we end up at the same stage i.e. I get the AWS credentials, by calling:
await _credential.getAwsCredentials(
idToken,
'accounts.google.com',
);
and this is essentially the same as JS:
// Obtain AWS credentials
AWS.config.credentials.get(function(){
// Access AWS resources here.
});
Do I understand correctly, that from this point on I'm authenticated and should use Google Sign In status to determine the session status?
Please try on this step:
final user = CognitoUser(
'xxx',
_userPool,
signInUserSession: session,
);
change your 'xxx'
to null
.
@orestesgaolin Did @furaiev 's solution resolve this? I am just about to start using this but want to know.
Nope, doesn't work for now
is there any update on this issue? I'm facing the same problem.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.