.net 访问cognito用户池并获取用户令牌

mzaanser  于 2023-11-20  发布在  .NET
关注(0)|答案(1)|浏览(88)

如何在Windows应用程序(WinForm)C#中从Cognito获取用户令牌。提前感谢。
我试

Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider = new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(
                 new Amazon.Runtime.AnonymousAWSCredentials(), Amazon.RegionEndpoint.USEast1);
userPool = new CognitoUserPool("", "", provider)

字符串

ctehm74n

ctehm74n1#

有一个C# example in the AWS SDK Code Examples library演示了如何使用用户池。您可以克隆存储库并自己运行该示例。那里有一个Admin Login部分,与您进行用户(非admin)登录时所需的内容类似。此设置使用了一个auth challenge,如果您不使用该选项,则可以忽略该选项。

public async Task<InitiateAuthResponse> InitiateAuthAsync(string clientId, string userName, string password)
{
    var authParameters = new Dictionary<string, string>();
    authParameters.Add("USERNAME", userName);
    authParameters.Add("PASSWORD", password);

    var authRequest = new InitiateAuthRequest

    {
        ClientId = clientId,
        AuthParameters = authParameters,
        AuthFlow = AuthFlowType.USER_PASSWORD_AUTH,
    };

    var response = await _cognitoService.InitiateAuthAsync(authRequest);
    Console.WriteLine($"Result Challenge is : {response.ChallengeName}");

    return response;
}

字符串

相关问题