我正在努力将用户池和身份与AWS Cognito集成。我不确定我是否应该在用户注册或登录时对用户进行身份验证。现在这是我的登录方式。
AWSCognitoIdentityUser *user = [self.pool getUser:self.emailField.text];
[[user getSession:self.emailField.text password:self.passwordField.text validationData:nil scopes:nil] continueWithBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserSession *> * _Nonnull task){
dispatch_async(dispatch_get_main_queue(), ^{
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:IdentityPool identityProviderManager:self.pool];
[credentialsProvider getIdentityId];
[credentialsProvider credentials];
if(task.error)
{
[SVProgressHUD dismiss];
UIAlertController *alert = [alertViewController passwordsDontMatch];
[self presentViewController:alert animated:YES completion:nil];
}
else
{
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:@"Enter" sender:self];
}
});
这是我的AppDelegate。
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = serviceConfiguration;
AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:ClientID clientSecret:ClientSecretId poolId:UserPoolId];
[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration:serviceConfiguration userPoolConfiguration:configuration forKey:@"UserPool"];
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
self.credentialProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:IdentityPoolId];
AWSServiceConfiguration *config = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:self.credentialProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = config;
答案 0 :(得分:0)
您对用户进行身份验证的时间将取决于应用程序的需求(用户体验和安全性)。对于可能需要进行电子邮件验证的某些应用,则仅在注册时不适合对用户进行身份验证。如果在注册时没有安全漏洞来验证用户,那么您也可以这样做。