我想为我的应用程序创建一个只有我的应用程序才能访问的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的应用程序可以访问我的应用程序接口?是否需要保存此id并在访问api时使用?
谢谢。
发布于 2016-08-15 12:51:08
使用'AWS_IAM‘授权保护应用编程接口将需要使用同一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版、安卓版和JavaScript版。
http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html
https://stackoverflow.com/questions/38890643
复制相似问题