src/AWSSDK.Extensions.CognitoAuthentication/CognitoUserAuthentication.cs
/// <summary>
/// Initiates the asynchronous SRP authentication flow
/// </summary>
/// <param name="srpRequest">InitiateSrpAuthRequest object containing the necessary parameters to
/// create an InitiateAuthAsync API call for SRP authentication</param>
/// <returns>Returns the AuthFlowResponse object that can be used to respond to the next challenge, 
/// if one exists</returns>
Initiates the asynchronous SRP authentication flow
Initiates the asynchronous SRP authentication flow
public void StartWithSrpAuthAsync(InitiateSrpAuthRequest srpRequest, AsyncCallback<AuthFlowResponse> callback = null)
        {
            if (srpRequest == null || string.IsNullOrEmpty(srpRequest.Password))
            {
                throw new ArgumentNullException("Password required for authentication.", "srpRequest");
            }
            Tuple<BigInteger, BigInteger> tupleAa = AuthenticationHelper.CreateAaTuple();
            InitiateAuthRequest initiateRequest = CreateSrpAuthRequest(tupleAa);
            Provider.InitiateAuthAsync(initiateRequest, initResult =>
            {
                if (initResult.Exception != null)
                {
                    callback?.Invoke(new AsyncResult<AuthFlowResponse>(null, initResult.Exception));
                    return;
                }
                UpdateUsernameAndSecretHash(initResult.Response.ChallengeParameters);
                RespondToAuthChallengeRequest challengeRequest =
                    CreateSrpPasswordVerifierAuthRequest(initResult.Response, srpRequest.Password, tupleAa);
                bool challengeResponsesValid = challengeRequest != null && challengeRequest.ChallengeResponses != null;
                bool deviceKeyValid = Device != null && !string.IsNullOrEmpty(Device.DeviceKey);
                if (challengeResponsesValid && deviceKeyValid)
                {
                    challengeRequest.ChallengeResponses.Add(CognitoConstants.ChlgParamDeviceKey, Device.DeviceKey);
                }
                Provider.RespondToAuthChallengeAsync(challengeRequest, respondResult =>
                {
                    if (respondResult.Exception != null)
                    {
                        callback?.Invoke(new AsyncResult<AuthFlowResponse>(null, respondResult.Exception));
                        return;
                    }
                    RespondToAuthChallengeResponse verifierResponse = respondResult.Response;
                    UpdateSessionIfAuthenticationComplete(verifierResponse.ChallengeName, verifierResponse.AuthenticationResult);
                    callback?.Invoke(new AsyncResult<AuthFlowResponse>(new AuthFlowResponse()
                    {
                        SessionID = verifierResponse.Session,
                        ChallengeName = verifierResponse.ChallengeName,
                        AuthenticationResult = verifierResponse.AuthenticationResult,
                        ChallengeParameters = verifierResponse.ChallengeParameters,
                        ClientMetadata = new Dictionary<string, string>(verifierResponse.ResponseMetadata.Metadata)
                    }, null));
                });
            });
        }
public void StartWithSrpAuthAsync ( InitiateSrpAuthRequest srpRequest , AsyncCallback < AuthFlowResponse > callback = null ) { if ( srpRequest == null || string . IsNullOrEmpty ( srpRequest . Password ) ) { throw new ArgumentNullException ( " " , " " ) ; } Tuple < BigInteger , BigInteger > tupleAa = AuthenticationHelper . CreateAaTuple ( ) ; InitiateAuthRequest initiateRequest = CreateSrpAuthRequest ( tupleAa ) ; Provider . InitiateAuthAsync ( initiateRequest , initResult => { if ( initResult . Exception != null ) { callback ? . Invoke ( new AsyncResult < AuthFlowResponse > ( null , initResult . Exception ) ) ; return ; } UpdateUsernameAndSecretHash ( initResult . Response . ChallengeParameters ) ; RespondToAuthChallengeRequest challengeRequest = CreateSrpPasswordVerifierAuthRequest ( initResult . Response , srpRequest . Password , tupleAa ) ; bool challengeResponsesValid = challengeRequest != null && challengeRequest . ChallengeResponses != null ; bool deviceKeyValid = Device != null && ! string . IsNullOrEmpty ( Device . DeviceKey ) ; if ( challengeResponsesValid && deviceKeyValid ) { challengeRequest . ChallengeResponses . Add ( CognitoConstants . ChlgParamDeviceKey , Device . DeviceKey ) ; } Provider . RespondToAuthChallengeAsync ( challengeRequest , respondResult => { if ( respondResult . Exception != null ) { callback ? . Invoke ( new AsyncResult < AuthFlowResponse > ( null , respondResult . Exception ) ) ; return ; } RespondToAuthChallengeResponse verifierResponse = respondResult . Response ; UpdateSessionIfAuthenticationComplete ( verifierResponse . ChallengeName , verifierResponse . AuthenticationResult ) ; callback ? . Invoke ( new AsyncResult < AuthFlowResponse > ( new AuthFlowResponse ( ) { SessionID = verifierResponse . Session , ChallengeName = verifierResponse . ChallengeName , AuthenticationResult = verifierResponse . AuthenticationResult , ChallengeParameters = verifierResponse . ChallengeParameters , ClientMetadata = new Dictionary < string , string > ( verifierResponse . ResponseMetadata . Metadata ) } , null ) ) ; } ) ; } ) ; }
Initiates the asynchronous SRP authentication flow
Initiates the asynchronous SRP authentication flow
Returns the AuthFlowResponse object that can be used to respond to the next challenge,
if one exists
Returns the AuthFlowResponse object that can be used to respond to the next challenge if one exists
srpRequest
InitiateSrpAuthRequest
InitiateSrpAuthRequest object containing the necessary parameters to
create an InitiateAuthAsync API call for SRP authentication
InitiateSrpAuthRequest object containing the necessary parameters to create an InitiateAuthAsync API call for SRP authentication
callback
AsyncCallback<AuthFlowResponse>