【问题标题】:How to use cognito to authenticate user by using mobile hub?如何使用 cognito 通过移动集线器对用户进行身份验证?
【发布时间】:2017-03-12 11:57:58
【问题描述】:

我是第一次尝试使用 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 中的 defaultServiceConfiguration 默认服务管理器]。对此对象的引用由 SDK,无需手动保留。如果 凭证提供者不是 AWSCognitoCredentials 的实例 提供者。

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

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

我在 Cognito 服务中签入了身份浏览器。新身份已创建,但没有数据集。会不会是与角色和 IAM 相关的东西?

【问题讨论】:

    标签: ios amazon-web-services amazon-cognito aws-mobilehub


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      • 2017-12-03
      • 2018-12-26
      • 1970-01-01
      • 2016-08-18
      相关资源
      最近更新 更多