aws / aws-aspnet-cognito-identity-provider

ASP.NET Core Identity Provider for Amazon Cognito
https://aws.amazon.com/developer/language/net/
Apache License 2.0
213 stars 89 forks source link

Sample not working properly - Unable to get IAM security credentials from EC2 Instance Metadata Service. #208

Closed efeozyer closed 2 years ago

efeozyer commented 2 years ago

Description

Sample not working properly.

Reproduction Steps

I've created Cognito userpool, with default settings. I created account I replaced configration under AWS section Start debugging Login

Logs

AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service. Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials() Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials() Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync() Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.RetryHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.RetryHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.MetricsHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Extensions.CognitoAuthentication.CognitoUserPool.FindByIdAsync(string userID) Amazon.AspNetCore.Identity.Cognito.CognitoUserStore<TUser>.FindByIdAsync(string userId, CancellationToken cancellationToken) in CognitoUserStore.IUserRoleStore.cs + var user = await _pool.FindByIdAsync(userId).ConfigureAwait(false); Amazon.AspNetCore.Identity.Cognito.CognitoUserManager<TUser>.FindByIdAsync(string userId) in CognitoUserManager.cs + var user = await _userStore.FindByIdAsync(userId, CancellationToken).ConfigureAwait(false); Amazon.AspNetCore.Identity.Cognito.CognitoSignInManager<TUser>.PasswordSignInAsync(string userId, string password, bool isPersistent, bool lockoutOnFailure) in CognitoSigninManager.cs + var user = await _userManager.FindByIdAsync(userId).ConfigureAwait(false); Samples.Areas.Identity.Pages.Account.LoginModel.OnPostAsync(string returnUrl) in Login.cshtml.cs + var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false); Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Convert<T>(object taskAsObject)

Environment

.Net5, Windows 10 aws-cli installation status: NOT


This is a :bug: bug-report

ashishdhingra commented 2 years ago

Hi @efeozyer,

Good morning.

Thanks for opening the issue. The error above is coming from the default credential resolution chain where SDK is unable to find the AWS credentials. The details could be found at Credential and profile resolution, where Amazon EC2 instance metadata is the last one to be resolved. Could you please share how you have configured your credentials? Simply configuring Cognito configuration would not work since you need to configure AWS credentials in order to use AWS services.

Thanks, Ashish

efeozyer commented 2 years ago

Hi @ashishdhingra, You're right, when I add accessKey and secretKey issue fixed. IMHO we should add this point readme.md or configuration sectio.

Thanks, Efe

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.