- Home /
AWSSDK Cognito User Pool Authentication issue with StartWithSrpAuthAsync() in Unity 2018.2.0
I am attempting to follow the "authenticate with SRP" flow for AWS Cognito user pool authorization for .NET in my Unity 2018.2.0 project. The code for the authentication flow was provided by Amazon with their Cognito Authentication Extension Library for .NET post located at: https://aws.amazon.com/blogs/developer/cognitoauthentication-extension-library-developer-preview/
Here is my code attached to a button in my unity scene:
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); // this line is performed but nothing afterwards is
authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() {
Password = userPassword
}).ConfigureAwait(false);
Debug.Log(user.SessionTokens.IdToken);
Debug.Log("Success");
}
}
I have all the AWS .dll resources in my assets (AWSSDK.Core, AWSSDK.SecurityToken, AWSSDK.CognitoIdentityProvider, and SAWSSDK.Extension.CognitoAuthentication) and get no errors in VS2017 or Unity. The code runs fine up to the call for await StartWithSrpAuthAsync(). Calling this function however results in no exceptions, results, or errors and never makes it to the next line.
I cannot find any other posts replicating this issue, but found several where this seemed to work fine. Any help would be much appreciated.
Were you able to get this fixed? I am in a similar situation. When trying to do this ( provider = new AmazonCognitoIdentityProviderClient(null, CognitoIdentityRegion);
) I get an exception as "Value cannot be null. Parameter name: stream"
Your answer
![](https://koobas.hobune.stream/wayback/20220612171647im_/https://answers.unity.com/themes/thub/images/avi.jpg)