gpt4 book ai didi

ios - AWS Cognito 匿名/ guest 用户的 IdentityId 更改

转载 作者:行者123 更新时间:2023-12-02 03:30:37 32 4
gpt4 key购买 nike

我很高兴在我的预发布应用程序 (iOS/Objective-C) 中使用 Cognito Sync,并登录 Facebook。然而,在提交苹果应用商店审核后,我被要求删除 Facebook 登录信息。我认为这很简单 - 只需更改 unauth 角色策略以匹配 auth 用户并绕过与 Facebook 身份验证有关的任何内容。

但是,现在我发现 IdentityId 在 session 之间发生变化。它的行为就像一个 session ID。这是一个令人头疼的问题,因为我的应用程序使用 IdentityId 作为 DynamoDB 中的哈希键。因此,例如,对当前用户最近事件的 DynamoDB 搜索仅显示当前 session 的历史记录,而不是预期的所有历史记录。

我正在使用示例应用程序的代码来获取identityId - 它似乎已正确分配。基于示例的 AWSIdentityManager.m,以下是 didFinishLaunchingWithOptions 内 AppDelegate.m 的一部分:

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: Could not obtain identity id: %@", task.error);
}
else {
// the task result will contain the identity id
NSString *cognitoId = task.result;
NSLog(@"Got the identity ID as %@", cognitoId);
// Don't change the 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;
}];

我不断收到新旧身份不一样的消息。此外,当我检查 Cognito Sync 时,无法再找到旧身份。

现在没有使用 Facebook SignIn 提供程序,如何确保 IdentityId 不会在 session 等之间发生更改?有人可以解释为什么这种情况会发生变化吗?我已确认我没有清除代码中任何地方的钥匙串(keychain)。

最佳答案

使用 AWSCognitoCredentialsProvider 时,identityid 会在本地缓存,并将在提供程序实例化时检索以供重用。

可能的解决方案:(1) 要获取身份 ID,请使用“credentialsProvider.identityId”而不是“getIdentityId”(2) 确保关闭应用程序时没有调用clearCredentials或clearKeyChain

评论:使用 unauth 很好,但是如果用户删除其应用程序或从不同的设备登录,则无法再次获得相同的身份(因为它们未经身份验证)。如果您需要用户能够跨设备/应用安装访问相同的数据,您将需要某种身份验证

关于ios - AWS Cognito 匿名/ guest 用户的 IdentityId 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34620614/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com