Implementation for accessing CognitoIdentityProvider Using the Amazon Cognito Your User Pools API, you can create a user pool to manage directories and users. You can authenticate a user to obtain tokens related to user identity and access policies.

This API reference provides information about user pools in Amazon Cognito Your User Pools.

For more information, see the Amazon Cognito Documentation.

Inheritance: AmazonServiceClient, IAmazonCognitoIdentityProvider
示例#1
0
    internal async Task <CognitoUser> ValidateUser(string username, string password)
    {
        Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
            new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());

        CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

        CognitoUser            user        = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);
        InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
        {
            Password = password
        };


        AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);

        if (authResponse.AuthenticationResult != null)
        {
            return(user);
        }
        else
        {
            return(null);
        }
    }
示例#2
0
    internal async Task <CognitoUser> ResetPassword(string username)
    {
        AAmazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
            new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());

        CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

        CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);
        await user.ForgotPasswordAsync();

        return(user);
    }
示例#3
0
    internal async Task <bool> VerifyAccessCode(string username, string code)
    {
        Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
            new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());
        ConfirmSignUpRequest confirmSignUpRequest = new ConfirmSignUpRequest();

        confirmSignUpRequest.Username         = username;
        confirmSignUpRequest.ConfirmationCode = code;
        confirmSignUpRequest.ClientId         = CLIENTAPP_ID;
        try
        {
            ConfirmSignUpResponse confirmSignUpResult = provider.ConfirmSignUp(confirmSignUpRequest);
            Console.WriteLine(confirmSignUpResult.ToString());
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return(false);
        }

        return(true);
    }
示例#4
0
    internal async Task <bool> SignUpUser(string username, string password, string email, string phonenumber)
    {
        Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
            new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());

        SignUpRequest signUpRequest = new SignUpRequest();

        signUpRequest.ClientId = CLIENTAPP_ID;
        signUpRequest.Username = username;
        signUpRequest.Password = password;


        AttributeType attributeType = new AttributeType();

        attributeType.Name  = "phone_number";
        attributeType.Value = phonenumber;
        signUpRequest.UserAttributes.Add(attributeType);

        AttributeType attributeType1 = new AttributeType();

        attributeType1.Name  = "email";
        attributeType1.Value = email;
        signUpRequest.UserAttributes.Add(attributeType1);


        try
        {
            SignUpResponse result = await provider.SignUpAsync(signUpRequest);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            return(false);
        }
        return(true);
    }