aws-sdk-ios
aws-sdk-ios copied to clipboard
Get cognito identity id use object c
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);
}
Can you clarify a few points?
-
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 ofid1
- User A signs out
- User B signs in
- App calls
-[credentialsProvider getIdentityId]
and gets a value ofid1
Is that a correct description of the steps where you're seeing this behavior?
-
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, thegetIdentityId
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? -
You invoke
-[credentialsProvider clearCredentials]
on your signOut notification handler, butclearCredentials
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?
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 ?
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/