diff --git a/src/Amazon.Extensions.CognitoAuthentication/CognitoUser.cs b/src/Amazon.Extensions.CognitoAuthentication/CognitoUser.cs index 5758708..a3a521b 100644 --- a/src/Amazon.Extensions.CognitoAuthentication/CognitoUser.cs +++ b/src/Amazon.Extensions.CognitoAuthentication/CognitoUser.cs @@ -123,13 +123,8 @@ public CognitoUser(string userID, string clientID, } this.ClientSecret = clientSecret; - if (!string.IsNullOrEmpty(clientSecret)) - { - this.SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(userID, clientID, clientSecret); - } this.UserID = userID; - this.Username = userID; if (!string.IsNullOrEmpty(username)) { this.Username = username; @@ -139,6 +134,11 @@ public CognitoUser(string userID, string clientID, this.Username = userID; } + if (!string.IsNullOrEmpty(clientSecret)) + { + this.SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(Username, clientID, clientSecret); + } + this.Status = status; this.UserPool = pool; diff --git a/src/Amazon.Extensions.CognitoAuthentication/CognitoUserAuthentication.cs b/src/Amazon.Extensions.CognitoAuthentication/CognitoUserAuthentication.cs index 361ffd7..aa15a52 100644 --- a/src/Amazon.Extensions.CognitoAuthentication/CognitoUserAuthentication.cs +++ b/src/Amazon.Extensions.CognitoAuthentication/CognitoUserAuthentication.cs @@ -66,7 +66,7 @@ public virtual async Task StartWithSrpAuthAsync(InitiateSrpAut if (srpRequest.IsCustomAuthFlow) { initiateRequest.AuthFlow = AuthFlowType.CUSTOM_AUTH; - initiateRequest.AuthParameters.Add("CHALLENGE_NAME", "SRP_A"); + initiateRequest.AuthParameters.Add(CognitoConstants.ChlgParamChallengeName, CognitoConstants.ChlgParamSrpA); } InitiateAuthResponse initiateResponse = await Provider.InitiateAuthAsync(initiateRequest, cancellationToken).ConfigureAwait(false); UpdateUsernameAndSecretHash(initiateResponse.ChallengeParameters); @@ -132,7 +132,7 @@ private RespondToAuthChallengeRequest CreateDeviceSrpAuthRequest(RespondToAuthCh RespondToAuthChallengeRequest authChallengeRequest = new RespondToAuthChallengeRequest() { - ChallengeName = "DEVICE_SRP_AUTH", + ChallengeName = ChallengeNameType.DEVICE_SRP_AUTH, ClientId = ClientID, Session = challenge.Session, ChallengeResponses = new Dictionary @@ -143,9 +143,8 @@ private RespondToAuthChallengeRequest CreateDeviceSrpAuthRequest(RespondToAuthCh } }; - if (!string.IsNullOrEmpty(ClientSecret)) + if (!string.IsNullOrEmpty(SecretHash)) { - SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(Username, ClientID, ClientSecret); authChallengeRequest.ChallengeResponses.Add(CognitoConstants.ChlgParamSecretHash, SecretHash); } return authChallengeRequest; @@ -192,9 +191,8 @@ private RespondToAuthChallengeRequest CreateDevicePasswordVerifierAuthRequest(Re {CognitoConstants.ChlgParamDeviceKey, Device.DeviceKey } }; - if (!string.IsNullOrEmpty(ClientSecret)) + if (!string.IsNullOrEmpty(SecretHash)) { - SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(Username, ClientID, ClientSecret); srpAuthResponses.Add(CognitoConstants.ChlgParamSecretHash, SecretHash); } @@ -814,9 +812,8 @@ private RespondToAuthChallengeRequest CreateSrpPasswordVerifierAuthRequest(Initi {CognitoConstants.ChlgParamTimestamp, timeStr }, }; - if (!string.IsNullOrEmpty(ClientSecret)) + if (!string.IsNullOrEmpty(SecretHash)) { - SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(Username, ClientID, ClientSecret); srpAuthResponses.Add(CognitoConstants.ChlgParamSecretHash, SecretHash); }