2016-06-14 113 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)正在注册不允许您访问。在用户注册时,您不会获得令牌,但需要以后登录。这已经处理完毕。