简体   繁体   中英

Integrating User Pools and Identity Pools Objective-C

I am struggling to integrate user pools and identity with AWS Cognito. I am not sure if i should be authenticating the users when they register or when they sign-in. Right now this is what my sign-in method looks like.

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


        });

This is my 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;

The time that you authenticate users will be based off of the needs of the app (User Experience and Security). For some apps where email verification may be required, then it is not fit to authenticate the user simply upon registration. If there is no security vulnerability to authenticating the user upon registering, then you may do it that way as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM