繁体   English   中英

对Amazon Cognito的AWS身份验证

[英]AWS authentication to Amazon Cognito

我是移动设备上的新手。 我正在尝试向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;

    }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM