1

将 AWS-SDK for .NET dll 包括 AWS.Extension.CognitoAuthentication 导入 Unity 2018.2 后,我遇到了https://aws.amazon.com/blogs/developer/cognitoauthentication-extension提供的StartWithSrpAuthAsync函数的问题-库开发者预览/AuthenticateWithSrpAsync

来自网站的代码:

public async void AuthenticateWithSrpAsync()
{
    var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(),
                                                           FallbackRegionFactory.GetRegionEndpoint());
    CognitoUserPool userPool = new CognitoUserPool("poolID", "clientID", provider);
    CognitoUser user = new CognitoUser("username", "clientID", userPool, provider);

    string password = "userPassword";



    AuthFlowResponse context = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest()
    {
        Password = password
    }).ConfigureAwait(false);

}

}

我想要一个按钮脚本从用户那里获取用户名和密码,并使用我在 Cognito 中创建的 UserPool 对其进行身份验证。

按钮脚本

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Amazon;
using Amazon.Runtime;
using Amazon.CognitoIdentityProvider;
using Amazon.Extensions.CognitoAuthentication;


public class test : MonoBehaviour {

public string userName;
public string userPassword;
public string clientID;
public string poolID;


public AuthFlowResponse authResponse;
public CognitoUserPool userPool;
public AmazonCognitoIdentityProviderClient provider;
public CognitoUser user;

void Start()
{

}
public void OnClick()
{
    try
    {
        AuthenticateWithSrpAsync();
    }
    catch(Exception ex)
    {
        Debug.Log(ex);
    }

}

public async void AuthenticateWithSrpAsync()
{
    RegionEndpoint CognitoIdentityRegion = RegionEndpoint.USEast1;
    provider = new AmazonCognitoIdentityProviderClient(null, CognitoIdentityRegion);
    userPool = new CognitoUserPool(poolID, clientID, provider, null);
    user = new CognitoUser(userName, clientID, userPool, provider);
    string name = user.Username.ToString();
    Debug.Log(name);
    authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() {

        Password = userPassword

    }).ConfigureAwait(false);
    Debug.Log(user.SessionTokens.IdToken);
    Debug.Log("Success");
}

}

应用程序客户端不需要密钥。

应用客户端

https://imgur.com/a/NUzBghb

用户状态已确认/启用,电子邮件已验证。

用户

https://imgur.com/lsnG5tT

最终发生的是脚本运行,直到它到达:

authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() {

    Password = userPassword

}).ConfigureAwait(false);
Debug.Log(user.SessionTokens.IdToken);
Debug.Log("Success");

之后绝对什么都不做。控制台中不显示任何调试以及任何错误或警告消息。

统一控制台:

https://imgur.com/Hxpcmoj

我查看了 StackOverflow 问题以及我在 google 上可以找到的所有其他资源。我也在 Unity 2017.3 中复制了这一点

我正在使用 .NetFramework 4.6

4

2 回答 2

0

我不认为它与 Unity 相关,因为相同的代码在我的最后工作正常。您可以尝试以下操作:_provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), );

于 2018-08-02T03:15:52.133 回答
0

尝试选中链接https://imgur.com/a/NUzBghb中的图像中显示的复选框“启用用户名密码(非 SRP)...。

于 2018-07-27T01:25:01.930 回答