William Lay

William Lay

  • NA
  • 31
  • 2.9k

Cognito and ASP.NET C# problem

Nov 18 2020 11:05 PM
I have been trying to get the session and the details of the current user after he has successfully logged in into the system as seen in the code below. However, I am not very sure how to get the session and details of the current user, the one i saw was through Javascript. Is there any way to use ASP.NET C# code to get those details? 
 
Here is my code :
 
  1.          const string PoolID = "id";  
  2.          const string ClientID = "id";  
  3.          static Amazon.RegionEndpoint Region = Amazon.RegionEndpoint.USEast1;  
  4.          protected void Page_Load(object sender, EventArgs e)  
  5.          {  
  6.             string username = "1";  
  7.             string password = "2";  
  8.             string email = "3";  
  9.             SignInUser(username,password);   
  10.         }  
  11.         static async Task<int> SignInUser(string username, string password)  
  12.         {  
  13.             AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), Region);  
  14.   
  15.             CognitoUserPool userPool = new CognitoUserPool(PoolID, ClientID, provider);  
  16.   
  17.             CognitoUser user = new CognitoUser(username, ClientID, userPool, provider);  
  18.   
  19.             InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()  
  20.             {  
  21.                 Password = password  
  22.             };  
  23.   
  24.             AuthFlowResponse authResponse = null;  
  25.             try  
  26.             {  
  27.                 authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);  
  28.             }  
  29.   
  30.             catch (Exception ex)  
  31.             {  
  32.                 System.Diagnostics.Debug.WriteLine("Logon Failed: {0}\n", ex.Message);  
  33.                 return 0;  
  34.             }  
  35.   
  36.             GetUserRequest getUserRequest = new GetUserRequest();  
  37.             getUserRequest.AccessToken = authResponse.AuthenticationResult.AccessToken;  
  38.   
  39.             System.Diagnostics.Debug.WriteLine(authResponse.AuthenticationResult.AccessToken);  
  40.             System.Diagnostics.Debug.WriteLine("Logon Successful");  
  41.             return 1;  
  42.         }  
 Any help will be appreciated. Thank You.
 
 
 

Answers (2)