Пример #1
0
        /// <summary>
        /// Initiates the asynchronous custom authentication flow
        /// </summary>
        /// <param name="customRequest">InitiateCustomAuthRequest object containing the necessary parameters to
        /// create an InitiateAuthAsync API call for custom authentication</param>
        /// <returns>Returns the AuthFlowResponse object that can be used to respond to the next challenge,
        /// if one exists</returns>
        public void StartWithCustomAuthAsync(InitiateCustomAuthRequest customRequest, AsyncCallback <AuthFlowResponse> callback = null)
        {
            InitiateAuthRequest authRequest = new InitiateAuthRequest()
            {
                AuthFlow       = AuthFlowType.CUSTOM_AUTH,
                AuthParameters = new Dictionary <string, string>(customRequest.AuthParameters),
                ClientId       = ClientID,
                ClientMetadata = new Dictionary <string, string>(customRequest.ClientMetadata)
            };

            Provider.InitiateAuthAsync(authRequest, r =>
            {
                if (r.Exception != null)
                {
                    callback?.Invoke(new AsyncResult <AuthFlowResponse>(null, r.Exception));
                    return;
                }

                InitiateAuthResponse initiateResponse = r.Response;
                UpdateUsernameAndSecretHash(initiateResponse.ChallengeParameters);

                UpdateSessionIfAuthenticationComplete(initiateResponse.ChallengeName, initiateResponse.AuthenticationResult);

                callback?.Invoke(new AsyncResult <AuthFlowResponse>(new AuthFlowResponse()
                {
                    SessionID            = initiateResponse.Session,
                    ChallengeName        = initiateResponse.ChallengeName,
                    AuthenticationResult = initiateResponse.AuthenticationResult,
                    ChallengeParameters  = initiateResponse.ChallengeParameters,
                    ClientMetadata       = new Dictionary <string, string>(initiateResponse.ResponseMetadata.Metadata)
                }, null));
            });
        }
Пример #2
0
        /// <summary>
        /// Initiates the asynchronous custom authentication flow
        /// </summary>
        /// <param name="customRequest">InitiateCustomAuthRequest object containing the necessary parameters to
        /// create an InitiateAuthAsync API call for custom authentication</param>
        /// <returns>Returns the AuthFlowResponse object that can be used to respond to the next challenge,
        /// if one exists</returns>
        public async Task <AuthFlowResponse> StartWithCustomAuthAsync(InitiateCustomAuthRequest customRequest)
        {
            InitiateAuthRequest authRequest = new InitiateAuthRequest()
            {
                AuthFlow       = AuthFlowType.CUSTOM_AUTH,
                AuthParameters = new Dictionary <string, string>(customRequest.AuthParameters),
                ClientId       = ClientID,
                ClientMetadata = new Dictionary <string, string>(customRequest.ClientMetadata)
            };

            InitiateAuthResponse initiateResponse = await Provider.InitiateAuthAsync(authRequest).ConfigureAwait(false);

            UpdateUsernameAndSecretHash(initiateResponse.ChallengeParameters);

            UpdateSessionIfAuthenticationComplete(initiateResponse.ChallengeName, initiateResponse.AuthenticationResult);

            return(new AuthFlowResponse()
            {
                SessionID = initiateResponse.Session,
                ChallengeName = initiateResponse.ChallengeName,
                AuthenticationResult = initiateResponse.AuthenticationResult,
                ChallengeParameters = initiateResponse.ChallengeParameters,
                ClientMetadata = new Dictionary <string, string>(initiateResponse.ResponseMetadata.Metadata)
            });
        }