2016-08-18 115 views
11

我是移動開發新手。我試圖驗證到Amazon Cognito。 我首先使用用戶名,PIN,平臺和deviceToken使用自定義服務模型登錄到Credentials Provider - 然後我得到identityId,endPoint和令牌。我被告知,我需要交換我回來的令牌並刷新我的憑據,以便我對AWS CognitoS3進行驗證。但是所有的過程都很混亂,並且有很多不同的例子。我創建了一個SignInProvider,擴展了AWSSignInProvider來訪問 - (void)登錄:(void(^)(id result,NSError * error))completionHanlder;我在我的登錄方法中有我的令牌,端點和identityId。我該如何處理完成處理程序以及接下來的內容。AWS認證到亞馬遜Cognito

@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:@"[email protected]"]; 

     [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; 

    } 
+0

任務是什麼,你要完成?上傳一些特定於用戶的S3存儲桶?上傳/下載東西到整個應用程序的同一個存儲桶,而不管它是哪個用戶? – Msencenb

回答

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