После импорта AWS-SDK для .NET dll, включая AWS.Extension.CognitoAuthentication, в Unity 2018.2, у меня возникла проблема с функцией StartWithSrpAuthAsync
, взятой из AuthenticateWithSrpAsync
, предоставленной https://aws.amazon.com/blogs/developer/cognitoauthentication-extension-library-developer-preview/
Код с сайта:
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);
}
}
Я хочу, чтобы скрипт кнопки принимал имя пользователя и пароль от пользователя и аутентифицировал их с помощью UserPool, который я создал в Cognito.
Скрипт кнопки
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");
}
}
Клиент приложения не требует секретного ключа.
Клиент приложения
Статус пользователя подтвержден/включен, а электронная почта подтверждена.
Пользователь
В итоге происходит то, что скрипт работает до тех пор, пока не доберется до:
authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() {
Password = userPassword
}).ConfigureAwait(false);
Debug.Log(user.SessionTokens.IdToken);
Debug.Log("Success");
И вообще ничего потом не делает. Ни одна из отладок не отображается в консоли, а также сообщения об ошибках или предупреждения.
Консоль единства:
Я просмотрел вопросы StackOverflow, а также любой другой ресурс, который смог найти в Google. Я также повторил это в Unity 2017.3.
Я использую .NetFramework 4.6.