【问题标题】:Creating a private Amazon API Gateway创建私有 Amazon API 网关
【发布时间】:2016-12-17 20:31:27
【问题描述】:

我想为我的应用创建一个只能由我的应用访问的 api。我已将 AWS Cognito 身份添加到我的 appDelegate 中,如下所示:

 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;
}];

我如何使用返回的 gonitoId 来确保这是唯一具有该 id 的应用程序可以访问我的 api?访问api时需要保存这个id使用吗?

谢谢。

【问题讨论】:

    标签: ios amazon-web-services amazon-iam amazon-cognito aws-api-gateway


    【解决方案1】:

    使用“AWS_IAM”授权保护 API 需要使用同一 AWS 账户中的凭证对请求进行签名。除此之外,如果您可以控制帐户,那么您应该能够通过使用 API Gateway 操作和资源设置细粒度策略来确保只有 Cognito 角色可以访问。

    http://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html#api-gateway-calling-api-permissions

    该应用应在通过身份验证后接收 Cognito 凭据,以便您在 API Gateway SDK 中使用。生成的 SDK 在 iOS Android 和 JavaScript 中可用。

    http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html

    【讨论】:

      猜你喜欢
      • 2016-12-19
      • 1970-01-01
      • 2023-03-06
      • 2021-11-09
      • 1970-01-01
      • 2018-08-08
      • 2021-03-05
      • 2021-01-17
      • 1970-01-01
      相关资源
      最近更新 更多