furaiev / amazon-cognito-identity-dart-2

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
187 stars 114 forks source link

How to proceed after getting Open ID credentials (e.g. Google Sign In)? #166

Closed orestesgaolin closed 1 year ago

orestesgaolin commented 3 years ago

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.

CleanShot 2021-09-02 at 17 37 25@2x

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?

furaiev commented 3 years ago

I hope official documentation will help you https://docs.aws.amazon.com/cognito/latest/developerguide/google.html

orestesgaolin commented 3 years ago

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?

furaiev commented 3 years ago

Please try on this step:

final user = CognitoUser(
      'xxx',
      _userPool,
      signInUserSession: session,
    );

change your 'xxx' to null.

nyck33 commented 3 years ago

@orestesgaolin Did @furaiev 's solution resolve this? I am just about to start using this but want to know.

orestesgaolin commented 3 years ago

Nope, doesn't work for now

diegodavilac commented 2 years ago

is there any update on this issue? I'm facing the same problem.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.