0

我正在使用Amazon Cognito User Pools. 我正在尝试对用户进行身份验证。首先,他/她必须输入电话号码和密码,将发送一条短信以验证用户身份,在验证用户时,应Sign in通过phonenumberpassword

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

1 回答 1

0

1) Cognito 目前不公开 API 来检查用户名是否已经存在。您可以通过调用特定于用户名的 API 并根据返回的异常采取行动来解决此问题。如果您在本地考虑更多,您可以根据用户名检查会话以查看是否有人已经登录。

2) RefreshTokens API 用于在旧的访问令牌过期后获取新的访问令牌。使用您在身份验证中返回的刷新令牌来促进这一点。

3) 注册不会让您访问。在用户注册时,您不会获得令牌,但之后需要登录。这已经处理好了。

于 2016-07-19T22:17:00.093 回答