AWS Cognito 用户池登录缺少身份验证令牌

AWS Cognito User Pool Sign In Missing Authentication Token

我正在尝试使用 AWS Cognito 用户池在 Xamarin Forms 跨平台应用程序中对我的用户进行身份验证。

我可以使用 SignUpAysnc() 注册用户,我可以看到它填充在 AWS 控制台的用户池中。

CognitoUserPool userPool = AmazonUtils.UserPool;
Dictionary<string, string> userAttributes = new Dictionary<string, string>();

userAttributes.Add("email", email);
userAttributes.Add("given_name", given_name);
userAttributes.Add("family_name", family_name);
userAttributes.Add("gender", gender);
userAttributes.Add("birthdate", birthdate);
userAttributes.Add("address", address);
userAttributes.Add("locale", locale);
userAttributes.Add("phone_number", phone_number);

await userPool.SignUpAsync(email, Password, userAttributes, null);

然而,当我尝试使用提供的电子邮件和密码登录时,我不断收到此异常:

[0:] Missing Authentication Token

我当前的验证码是:

private async void LoginButton_Clicked(object sender, EventArgs e)
{
    AdminInitiateAuthRequest authRequest = new AdminInitiateAuthRequest();
    authRequest.ClientId = Constants.ClientID;
    authRequest.AuthParameters.Add("email", "test.user@email.com");
    authRequest.AuthParameters.Add("password", "Password12!");
    authRequest.UserPoolId = Constants.AuthPoolID;
    authRequest.AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH;

    try
    { 
        AdminInitiateAuthResponse response = await AmazonUtils.IdentityClientProvider.AdminInitiateAuthAsync(authRequest);
    }
    catch(Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
    }
}

有人知道我可能遗漏了什么吗?

问题是你需要先发起身份验证挑战,然后传递密码和加密字符串,其中包含池名称、用户名、秘密块和其他信息。

这是一个很好的 .Net 示例:http://blog.mmlac.com/aws-cognito-srp-login-c-sharp-dot-net/

请注意,您需要通过 NuGet 添加 Org.BouncyCastle.Math 和 Org.BouncyCastle.Security 到您的项目中才能编译它。

还有一个例子:https://gist.github.com/dbeattie71/44ea3a13145f185d303e620c299ab1c5

它看起来很有希望,但我没有检查它所以我不能保证它有效。从中您可以了解整个过程的样子。