2016-06-14 7 views
0

私はAmazon Cognito User Poolsを使用しています。私はユーザーを認証しようとしています。まず、電話番号とパスワードを入力する必要があります。にユーザが認証されると、phonenumberpasswordを入力して、ユーザを認証するためのSMSが送信されます。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; 


} 

私は現在、確認するためにAPIを公開していない - (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 APPDELEGATESに次のコードを追加しない限りstartPasswordAuthenticationが実行されることはありませんので、予めご了承くださいユーザー名がすでに存在する場合この問題を回避するには、ユーザー固有のAPIを呼び出し、スローされた例外に基づいて動作させることができます。よりローカルで考えている場合は、ユーザー名に基づいてセッションを確認して、誰かがすでにサインインしているかどうかを確認できます。012)2)RefreshTokens APIは、古いトークンが期限切れになったら新しいアクセストークンを取得するために使用します。これを容易にするために認証時に戻ったリフレッシュトークンを使用してください。

3)登録されていてもアクセスできません。ユーザー登録では、トークンは取得されませんが、後でログインする必要があります。これはすでに処理されています。

関連する問題