aws / aws-sdk-net-extensions-cognito

An extension library to assist in the Amazon Cognito User Pools authentication process
Apache License 2.0
102 stars 49 forks source link

Missing Authentication Token when trying to use ListUsersRequest #95

Closed LoopIssuer closed 1 year ago

LoopIssuer commented 1 year ago

Describe the bug

I got the error, when trying to use ListUsersRequest (in forgotten password flow )

Missing Authentication Token Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.

 private async Task<ListUsersResponse> FindUsersByEmailAddress(string mail)
        {
            ListUsersRequest listUsersRequest = new ListUsersRequest
            {
                UserPoolId = _cognitoCredentials.UserPoolId, 
                Filter = $"email=\"{mail}\""
            };
            return await _provider.ListUsersAsync(listUsersRequest);
        }

Expected Behavior

No error, get a list of registered users from Cognito.

Current Behavior

Error is thrown: Missing Authentication Token Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.

Reproduction Steps

Use this method to get list of available users:

private async Task<ListUsersResponse> FindUsersByEmailAddress(string mail)
        {
            ListUsersRequest listUsersRequest = new ListUsersRequest
            {
                UserPoolId = _cognitoCredentials.UserPoolId, 
                Filter = $"email=\"{mail}\""
            };
            return await _provider.ListUsersAsync(listUsersRequest);
        }

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Unity 2021.3.9 Aws sdk .net

Targeted .NET Platform

.Net 4.x

Operating System and version

Windows 11

ashishdhingra commented 1 year ago

Hi @TomaszWozniakMosina,

Good morning.

Unfortunately, the issue is not reproducible using the below code (only for demonstration purposes):

using Amazon.CognitoIdentityProvider;
using Amazon.CognitoIdentityProvider.Model;
using System.Threading.Tasks;

namespace TestConsoleApp_NetFramework
{
    internal class Program
    {
        static string userPoolId = "<<user-pool-id>>";

        static void Main(string[] args)
        {
            string email = "<<valid-email-address>>";
            var response = ListCognitoUsers(userPoolId, email).Result;
        }

        private static async Task<ListUsersResponse> ListCognitoUsers(string userPoolId, string email)
        {
            AmazonCognitoIdentityProviderClient client = new AmazonCognitoIdentityProviderClient(Amazon.RegionEndpoint.USEast2); // Set the region endpoint appropriately.
            var request = new ListUsersRequest() { UserPoolId = userPoolId, Filter = $"email=\"{email}\"" };
            return await client.ListUsersAsync(request);
        }
    }
}

Please check if you have configured the AWS credentials properly (with proper IAM policy/permission to list users) in your profile chain to access Cognito service.

Thanks, Ashish

github-actions[bot] commented 1 year ago

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.