2016-06-14 49 views
0

我正在使用Amazon Cognito User Pools。我正在嘗試驗證用戶。首先他/她將不得不輸入電話號碼和密碼,將會有一條短信發送給用戶進行身份驗證,通過給予phonenumberpassword認證用戶預計Sign in用戶使用Amazon Cognito登錄

1)我要彈出用戶註冊畫面,如果用戶不與該應用

2.)如果應用程序已經向我希望用戶使用的應用程序,而不必繼續進行背景註冊再次登錄。 (目前用戶需要一直登錄到後臺)

3.)如果用戶已經註冊但未驗證SMS驗證,那麼我想將用戶重定向到確認頁面

我一直在這裏呆了近一個禮拜。有人可以幫我嗎。

在應用程序委託我有以下代碼。 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

..

 AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; 



     //create a pool 

     AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:@"XXX" clientSecret:@"XXX" poolId:@"us-east-1_XXX"]; 

     [AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration:serviceConfiguration userPoolConfiguration:configuration forKey:@"UserPool"]; 

     //AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"]; 





     [AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose; 





     AWSCognitoIdentityUserPool *pool =[AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"]; 



     pool.delegate = self; 

} 



//set up password authentication ui to retrieve username and password from the user 

-(id<AWSCognitoIdentityPasswordAuthentication>) startPasswordAuthentication { 

//  

    if(!self.navController){ 

     self.navController = [[UIForViewController getStoryboard] instantiateViewControllerWithIdentifier:@"signupSegueID"]; 

    } 

// if(!self.signInViewController){ 

//  self.signInViewController = self.navigationController.viewControllers[0]; 

// } 



    dispatch_async(dispatch_get_main_queue(), ^{ 

     //rewind to login screen 



     //display login screen if it isn't already visibile 

     if(!(self.navController.isViewLoaded && self.navController.view.window)) 

     { 

      [self.window.rootViewController presentViewController:self.navController animated:YES completion:nil]; 

     } 

    }); 

    return nil; 


} 

請注意,startPasswordAuthentication永遠不會執行,除非我在APPDELEGATES添加以下代碼 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

[[self.user getDetails] continueWithSuccessBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserGetDetailsResponse *> * _Nonnull task) { 
    if (task.error) { 
     // 
     NSLog(@"Error "); 
     [[[UIAlertView alloc] initWithTitle:task.error.userInfo[@"__type"] 
            message:task.error.userInfo[@"message"] 
            delegate:self 
          cancelButtonTitle:@"Ok" 
          otherButtonTitles:nil] show]; 
     return nil; 
    } 
    AWSCognitoIdentityUserGetDetailsResponse *response = task.result; 



    for (AWSCognitoIdentityUserAttributeType *attribute in response.userAttributes) { 
     //print the user attributes 
     NSLog(@"Attribute: %@ Value: %@", attribute.name, attribute.value); 
    } 
    return nil; 
}]; 

回答

0

1)Cognito目前不公開的API來檢查如果用戶名已經存在。你可以通過調用一個用戶名特定的API來解決這個問題,並根據拋出的異常進行操作。如果你在本地考慮更多,你可以根據用戶名檢查會話,看看是否有人登錄。

2)RefreshTokens API用於在舊的訪問令牌過期後獲取新的訪問令牌。使用您在身份驗證中獲得的刷新令牌來促進此操作。

3)正在註冊不允許您訪問。在用戶註冊時,您不會獲得令牌,但需要以後登錄。這已經處理完畢。

相關問題