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

问题描述 投票:1回答:1

我正在尝试使用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", "[email protected]");
    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);
    }
}

有谁知道我可能会缺少什么?

amazon-web-services xamarin.forms aws-cognito
1个回答
0
投票

问题是您需要首先启动身份验证质询,然后传递密码以及包含池名称,用户名,密码块和其他信息的加密字符串。

这是一个很好的.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

它看起来很有希望,但我没有检查它,所以我无法保证它的工作原理。通过它,您可以了解整体流程的外观。

© www.soinside.com 2019 - 2024. All rights reserved.