aws-sdk-ios icon indicating copy to clipboard operation
aws-sdk-ios copied to clipboard

Get cognito identity id use object c

Open nstang01 opened this issue 5 years ago • 2 comments

I want to get the Cognito identity id use object c. This id is used as the user's UUID. But It is always the same when I switch users.pls give me some supports.

Provide code snippets (if applicable)

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionAPSoutheast2 identityPoolId:identityPoolId];

    AWSServiceConfiguration *defaultServiceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast2
            credentialsProvider:credentialsProvider];

    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = defaultServiceConfiguration;

    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"signOut" object:nil] subscribeNext:^(NSNotification * _Nullable x) {
     [credentialsProvider clearCredentials];
    }];
    
    [credentialsProvider.getIdentityId continueWithBlock:^id _Nullable(AWSTask<NSString *> * _Nonnull task) {
        if (task.error) {
            LM_queueMainStart
            UIAlertControllerAlertCreate(task.error.userInfo[@"__type"], task.error.userInfo[@"message"])
            .addDefaultAction(@"OK", 1)
            .actionTap(^(NSInteger index, UIAlertAction * _Nonnull action) {})
            .showFromViewController(self.window.rootViewController);
            LM_queueEnd
        }
        else {
             [self.mj_header endRefreshing];
            [credentialsProvider clearCredentials];
            
            NSString *cognitoId = task.result;
            
            NSLog(@"cognitoId----------%@",cognitoId);
}

nstang01 avatar Jan 07 '20 02:01 nstang01

Can you clarify a few points?

  1. When you say "switch users", I interpret that to mean the following steps:

    • User A signs in
    • App calls -[credentialsProvider getIdentityId] and gets a value of id1
    • User A signs out
    • User B signs in
    • App calls -[credentialsProvider getIdentityId] and gets a value of id1

    Is that a correct description of the steps where you're seeing this behavior?

  2. In the code snippet above, I don't see how you are signing in--specifically, I don't see whether you're waiting for a sign in to successfully complete before calling -[credentialsProvider getIdentityId]. Notably, the getIdentityId method does not make a remote call if an identity ID is already set on the provider, which means that if you invoke that method before the sign in completes and updates the local cache, it will return the old cached value. Do you still see this behavior if you only invoke getIdentityId after you have successfully signed in?

  3. You invoke -[credentialsProvider clearCredentials] on your signOut notification handler, but clearCredentials does not clear cached identity IDs--it only clears cached AWS credentials for the provider. In order to clear the identity ID, you will need to call -[credentialsProvider clearKeychain] (which both clears the identity ID and the cached credentials). Was it your intent to clear the identity ID as well as credentials?

palpatim avatar Jan 10 '20 20:01 palpatim

Thank you for your reply,

1.Yes,It's my steps.

2.I use Cognito user pool to sign in. Sign in successfully complete before calling this method.

3.When I use -[credentialsProvider clearKeychain] to clear the identity ID,I found identity ID always different, but I used the same count to sign in.

Am I missing any steps?Can you provide me with specific steps ?

nstang01 avatar Jan 11 '20 04:01 nstang01

Apologies for losing track on this, are you still facing this issue? We recommend using the latest Amplify library to retrieve credentials. You can find more details here - https://docs.amplify.aws/lib/auth/getting-started/q/platform/ios/

royjit avatar Dec 23 '22 19:12 royjit