【问题标题】:Point of using the AWS Cognito Identity使用 AWS Cognito 身份的要点
【发布时间】:2016-12-13 04:04:50
【问题描述】:

使用以下代码的目的是为了让我可以通过我的 ios 应用程序直接访问其他 AWS 工具吗?

    AWSCognitoCredentialsProvider *credentialsProvider = [[DeveloperAuthenticationProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"poolId"];

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

    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

    __block NSString *cognitoId = nil;

    // Retrieve your Amazon Cognito ID
    [[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task)
    {
        if (task.error)
        {
            NSLog(@"Error: %@", task.error);
        }
        else
        {
            // the task result will contain the identity id
            cognitoId = task.result;
        }

        return nil;
    }];

然后我使用 AWS Lambda 和 API 网关来获取用户身份。

【问题讨论】:

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


    【解决方案1】:

    为了在访问 AWS 资源时提供执行上下文(身份验证),需要 Cognito。这意味着,在 AWS 上没有什么是真正匿名的 - 即使您没有让您的用户“登录”,他们仍然拥有与其设备关联的唯一标识符。

    这意味着您的应用程序之外的某个随机人员不能简单地访问您的 AWS 资源(S3、Lambda 等)并执行代码。

    这也意味着您可以而且必须为您的 Lambda 分配执行权限,以允许您的 Cognito 组执行。

    另外需要注意的是:您无需使用 API 网关即可在 iOS 上执行 Lambda。您可以本机调用。我更喜欢这样做 - 更少的配置。

    http://docs.aws.amazon.com/mobile/sdkforios/developerguide/lambda.html

    希望能回答你的问题。

    【讨论】:

    • 如果我将此注释掉,我的网关功能仍然有效。因此,如果我尝试直接访问网关之外的任何内容,例如 s3,它就会失败。正确的?还使用网关访问 lambda,所以我可以发送东西 https://。谢谢。
    • 如果您可以在没有 Cognito 的情况下访问您的网关,那么世界上其他任何人都可以。你的功能是开放的。现在,也许您正在使用它来提供 REST 端点以将资产从 S3 提供给 Web。这就说得通了。此外,值得注意的是,来自 iOS 的所有原生 AWS API 调用都被转换为 https 调用到 AWS REST API。
    • 我不知道原生 https: 调用。如何使用 cognitoId 将我的 api 仅提供给我的用户?谢谢,
    猜你喜欢
    • 2014-10-04
    • 2016-10-02
    • 2018-01-29
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 2018-03-14
    • 2019-02-23
    • 2017-01-02
    相关资源
    最近更新 更多