我设置了一组 lambda 函数来完成我的所有身份验证。我通过 api 网关从我的应用程序连接,然后最后调用 GetOpenIdTokenForDeveloperIdentity()。这会通过网关向我的设备返回一个 identityId 和令牌。
接下来我按照本网站的说明(针对 Objective-C): http ://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html
因为我有 identityId 和 token,所以我从这个开始:
开发者提供者.h
#import <AWSCore/AWSCore.h>
@interface DeveloperProvider : AWSCognitoCredentialsProviderHelper
@end
开发者提供者.m
@implementation DeveloperProvider
/*
* Use the token method to communicate with your backend to get an
* identityId and token.
*/
// Below gave me an error and changed to: - (AWSTask <NSString *> *) token
- (AWSTask <NSString*>) token
{
//Write code to call your backend:
//Pass username/password to backend or some sort of token to authenticate user
//If successful, from backend call getOpenIdTokenForDeveloperIdentity with logins map
//containing "your.provider.name":"enduser.username"
//Return the identity id and token to client
//You can use AWSTaskCompletionSource to do this asynchronously
// Added this in to the code
NSString *identityId = @"IdentityIdFromGateway";
NSString *token = @"TokenGotFromGatewayToo";
// Changed below code from this:
// Set the identity id and return the token
// self.identityId = response.identityId;
// return [AWSTask taskWithResult:response.token];
// to this:
self.identityId = identityId;
return [AWSTask taskWithResult:token];
}
@end
我从上面得到两个错误:
- 在 .h 文件中,我得到“找不到 AWSCognitoCredentialsProviderHelper 的接口”
- 在 .m 文件中,我得到“identityId 是对只读属性 self.identityId 的分配”
我已经重新安装了 CocoaPods 并重新安装了 aws-ios-sdk。我什至清理了所有旧文件和派生数据。
我错过了什么吗?最终目标是能够让经过身份验证的用户能够直接从应用程序调用 dynamodb 和 s3,而无需再使用网关和 lambda,因为用户已通过身份验证。谢谢。