对Amazon Cognito进行AWS身份验证

时间:2016-08-18 13:50:23

标签: ios objective-c amazon-web-services authentication amazon-s3

我是移动设备上的新手。我正在尝试向Amazon Cognito进行身份验证。 我首先使用自定义服务模型使用用户名,密码,平台和deviceToken登录Credentials Provider - 然后我返回identityId,endPoint和token。我被告知我需要交换我回来的令牌并刷新我的凭据,以便我通过AWS CognitoS3进行身份验证。但是所有这些过程都令人困惑,并且有很多不同的例子。

我创建了一个SignInProvider,扩展了AWSSignInProvider来访问 - (void)登录:( void(^)(id result,NSError * error))completionHanlder;我在我的登录方法中有我的令牌,端点和identityId。我对完成处理程序做了什么,接下来是什么呢。

@implementation SignInProvider

+(instanceType) sharedInstance{}

- (NSString) identityProviderName{}

- (AWSTask<NSString*>*) token{}

- (BOOL) isLoggedIn{}

- (NSSting*) userName{}

- (void) reloadSession{}

- (void) login: (void (^) (id result, NSError *error)) completionHanlder{

authRequest = [IMPCLDMobileAuthenticationRequest new];



     [authRequest setToken:@"930fc1b56d8ca19a84500f9a79af71b65f60331f0242ce4395cdf41186443692"];

        [authRequest setPassword:@"pin"];

        [authRequest setUsername:@"example@email.co.za"];

        [authRequest setPlatform:@"ios"];

        serviceClient = [IMPCLDImpressionInternalMicroserviceClient defaultClient];


        [[serviceClient mobileAuthenticationPost:authRequest] continueWithBlock:^id(AWSTask *loginTask)
     {


    //what to do here with my loginTask results (token, endpoint, identityId)

        }

    return nil;

    }

1 个答案:

答案 0 :(得分:2)

要在AWS中交换/保存令牌,您需要在continueWithBlock

中进行以下操作
[[serviceClient mobileAuthenticationPost:authRequest] continueWithBlock:^id(AWSTask *loginTask)
 {
     AWSSNSCreateEndpointResponse *response = loginTask.result;
     AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new];
     subscribeRequest.endpoint = response.endpointArn;
     subscribeRequest.protocols = @"application";
     subscribeRequest.topicArn = YOUR_TOPIC_ARN;
     return [sns subscribe:subscribeRequest];
 }] continueWithBlock:^id(AWSTask *task) {
     if (task.cancelled) {
         NSLog(@"Task cancelled");
     }
     else if (task.error) {
         NSLog(@"Error occurred: [%@]", task.error);
     }
     else {
         NSLog(@"Success");
     }
     return nil;
 }];