繁体   English   中英

如何使用 Cognito 通过移动集线器对用户进行身份验证?

[英]How to use cognito to authenticate user by using mobile hub?

我第一次尝试使用 Mobile Hub。 我创建了一个示例应用程序,用户只能通过 facebook 登录。 我的主要问题是

  1. 如何找出这是用户第一次登录或之前存在
  2. 如何将数据同步到 AWS Cognito 数据集

为了解决第一个问题,我提出了这个解决方案来检查用户数据集是否为空,那么这是用户第一次加入。

为了在应用程序委托 didFinishLaunchingWithOptions 中做到这一点:

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
                                                      initWithRegionType:AWSRegionUSEast1
                                                      identityPoolId:@"us-east-1:pool id is here"];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];



[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

后来我试图这样做:

AWSCognito *syncClient = [AWSCognito defaultCognito];

// Create a record in a dataset and synchronize with the server
AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:@"Sample"];
[dataset setString:@"test2" forKey:@"test"];
[[dataset synchronize] continueWithBlock:^id(AWSTask *task) {
    // Your handler code here
    return nil;
}];

[dataset synchronize];

服务器上没有用户的数据集。 我正在尝试创建此数据集。 但问题是 [AWSCognito defaultCognito] 返回 null。 我检查了文档,它说:

返回单例服务客户端。 如果单例对象不存在,SDK 会使用 [AWSServiceManager defaultServiceManager] 中的 defaultServiceConfiguration 实例化默认服务客户端。 该对象的引用由 SDK 维护,您无需手动保留。 如果凭证提供程序不是 AWSCognitoCredentials 提供程序的实例,则返回 nil。

我不确定我错过了什么。 为什么当我调用这个单例时它返回 null!

如何检查凭证提供程序是否是 AWSCognitoCredentials 提供程序的实例?

我在 Cognito 服务中检查了身份浏览器。 新身份已创建,但没有数据集。 它可能与角色和 IAM 相关吗?

您应该遵循 AWS Mobile Hub 示例移动应用程序项目的示例,您可以从 Mobile Hub 的“集成”页面下载该项目。 假设您已在 Mobile Hub 项目中启用“用户数据存储”功能,该示例包含所有必需的 Info.plist 文件条目,这些条目将启用 Amazon Cognito。 您还应该通读 AWS Mobile Hub 控制台的“集成”页面中的所有集成说明,以确保您没有遗漏任何其他集成步骤。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM