【发布时间】:2021-05-21 07:35:49
【问题描述】:
我正在使用 .NET Core 3.1 开发 C# 客户端应用程序,该应用程序需要使用 AWS Cognito 用户池进行用户身份验证。
由于这是一个客户端应用程序,我不能使用AdminInitiateAuth 等,只能访问:用户池 ID、客户端 ID 以及用户提供的用户名和密码。
我正在从使用 https://www.npmjs.com/package/amazon-cognito-identity-js 的现有 JavaScript 客户端应用程序移植代码,但我正在努力寻找在 C# 中为 .NET Core 应用程序执行此操作的等效方法。
我确实找到了使用 CognitoAuthentication 扩展库 https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/cognito-authentication-extension.html 看起来很完美的东西,但是在尝试创建提供程序时程序无限期挂起的示例时:
public static async void GetCredsAsync()
{
AmazonCognitoIdentityProviderClient provider =
new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials()); // << hangs here
CognitoUserPool userPool = new CognitoUserPool("poolID", "clientID", provider);
CognitoUser user = new CognitoUser("username", "clientID", userPool, provider);
InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
{
Password = "userPassword"
};
AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
accessToken = authResponse.AuthenticationResult.AccessToken;
}
我不确定该示例是否与 .NET Core 相关 - 页面上的第一句话说它是,但顶部有一个横幅说它不是!横幅将我指向https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html,但我似乎无法在那里找到我需要的东西。
如何仅使用用户池 ID、客户端 ID 和用户提供的用户名和密码在 .Net Core 中获取 AWS Cognito 访问令牌?
(或者为什么在示例中创建 AmazonCognitoIdentityProviderClient 挂起?)
感谢您的帮助,谢谢
【问题讨论】:
标签: c# .net-core amazon-cognito