ios - AWS Cognito identityId changing for anonymous/guest users -
i happily using cognito sync pre-release app (ios/objective-c), facebook login. however, upon submitting apple app store review, asked remove facebook login. thought straightforward - changed unauth role policies match auth user , bypassed facebook authentication.
however, finding identityid changing between sessions. behaving session id. major headache because app uses identityid hash key in dynamodb. so, example, dynamodb search recent activities current user shows current session's history, not history intended.
i using sample app's code obtain identityid - seems getting assigned correctly. based on sample's awsidentitymanager.m, following part of appdelegate.m inside didfinishlaunchingwithoptions:
awscognitocredentialsprovider *credentialsprovider = [[awscognitocredentialsprovider alloc] initwithregiontype:amazon_cognito_region identitypoolid:amazon_cognito_identity_pool_id]; awsserviceconfiguration *configuration = [[awsserviceconfiguration alloc] initwithregion:amazon_cognito_region credentialsprovider:credentialsprovider]; awsservicemanager.defaultservicemanager.defaultserviceconfiguration = configuration; [[credentialsprovider getidentityid] continuewithblock:^id(awstask *task) { if (task.error) { nslog(@"error: not obtain identity id: %@", task.error); } else { // task result contain identity id nsstring *cognitoid = task.result; nslog(@"got identity id %@", cognitoid); // don't change id nsstring *oldid = [[nsuserdefaults standarduserdefaults] objectforkey:nsud_cognito_id]; if (!oldid) { [[nsuserdefaults standarduserdefaults] setobject:cognitoid forkey:nsud_cognito_id]; [[nsuserdefaults standarduserdefaults] synchronize]; } else { nslog(@"old = %@, new = %@, keeping old", oldid, cognitoid); } } return nil; }]; i keep getting message old , new identities not same. also, when check in cognito sync, old identities can no longer found.
now there no facebook signin provider in use, how ensure identityid not change across sessions etc? can shed light on why changing? have confirmed not clearing keychain anywhere in code.
when using awscognitocredentialsprovider identityid cached locally , retrieved on instantiation of provider re-use.
possible solutions: (1) identity id use "credentialsprovider.identityid" rather "getidentityid" (2) make sure not calling clearcredentials or clearkeychain when closing application
comments: using unauth fine, if user deletes application or logs in different device there no way same identity again (as unauthenticated). if need users able access same data across device/app installs need sort of authentication
Comments
Post a Comment