/// <summary> /// Multi-Factor authentication with Bandwidth Voice services. Allows for a user to send an MFA code via a phone call. /// </summary> /// <param name="accountId">Required parameter: Bandwidth Account ID with Voice service enabled.</param> /// <param name="body">Required parameter: Example: .</param> /// <returns>Returns the ApiResponse of Models.TwoFactorVoiceResponse response from the API call.</returns> public ApiResponse <Models.TwoFactorVoiceResponse> CreateVoiceTwoFactor( string accountId, Models.TwoFactorCodeRequestSchema body) { Task <ApiResponse <Models.TwoFactorVoiceResponse> > t = this.CreateVoiceTwoFactorAsync(accountId, body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Two-Factor authentication with Bandwidth Voice services /// </summary> /// <param name="accountId">Required parameter: Bandwidth Account ID with Voice service enabled</param> /// <param name="body">Required parameter: Example: </param> /// <return>Returns the ApiResponse<Models.TwoFactorVoiceResponse> response from the API call</return> public async Task <ApiResponse <Models.TwoFactorVoiceResponse> > CreateVoiceTwoFactorAsync(string accountId, Models.TwoFactorCodeRequestSchema body, CancellationToken cancellationToken = default) { //the base uri for api requests string _baseUri = config.GetBaseUri(Server.TwoFactorAuthDefault); //prepare query string for API call StringBuilder _queryBuilder = new StringBuilder(_baseUri); _queryBuilder.Append("/accounts/{accountId}/code/voice"); //process optional template parameters ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "accountId", accountId } }); //append request with appropriate headers and parameters var _headers = new Dictionary <string, string>() { { "user-agent", userAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" } }; //append body params var _body = ApiHelper.JsonSerialize(body); //prepare the API call request to fetch the response HttpRequest _request = GetClientInstance().PostBody(_queryBuilder.ToString(), _headers, _body); _request = await authManagers["twoFactorAuth"].ApplyAsync(_request).ConfigureAwait(false); //invoke request and get response HttpStringResponse _response = await GetClientInstance().ExecuteAsStringAsync(_request, cancellationToken).ConfigureAwait(false); HttpContext _context = new HttpContext(_request, _response); //Error handling using HTTP status codes if (_response.StatusCode == 400) { throw new InvalidRequestException("client request error", _context); } //handle errors defined at the API level base.ValidateResponse(_response, _context); var _result = ApiHelper.JsonDeserialize <Models.TwoFactorVoiceResponse>(_response.Body); ApiResponse <Models.TwoFactorVoiceResponse> apiResponse = new ApiResponse <Models.TwoFactorVoiceResponse>(_response.StatusCode, _response.Headers, _result); return(apiResponse); }
/// <summary> /// Multi-Factor authentication with Bandwidth Voice services. Allows for a user to send an MFA code via a phone call. /// </summary> /// <param name="accountId">Required parameter: Bandwidth Account ID with Voice service enabled.</param> /// <param name="body">Required parameter: Example: .</param> /// <param name="cancellationToken"> cancellationToken. </param> /// <returns>Returns the ApiResponse of Models.TwoFactorVoiceResponse response from the API call.</returns> public async Task <ApiResponse <Models.TwoFactorVoiceResponse> > CreateVoiceTwoFactorAsync( string accountId, Models.TwoFactorCodeRequestSchema body, CancellationToken cancellationToken = default) { // the base uri for api requests. string baseUri = this.Config.GetBaseUri(Server.MultiFactorAuthDefault); // prepare query string for API call. StringBuilder queryBuilder = new StringBuilder(baseUri); queryBuilder.Append("/accounts/{accountId}/code/voice"); // process optional template parameters. ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>() { { "accountId", accountId }, }); // append request with appropriate headers and parameters var headers = new Dictionary <string, string>() { { "user-agent", this.UserAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" }, }; // append body params. var bodyText = ApiHelper.JsonSerialize(body); // prepare the API call request to fetch the response. HttpRequest httpRequest = this.GetClientInstance().PostBody(queryBuilder.ToString(), headers, bodyText); if (this.HttpCallBack != null) { this.HttpCallBack.OnBeforeHttpRequestEventHandler(this.GetClientInstance(), httpRequest); } httpRequest = await this.AuthManagers["multiFactorAuth"].ApplyAsync(httpRequest).ConfigureAwait(false); // invoke request and get response. HttpStringResponse response = await this.GetClientInstance().ExecuteAsStringAsync(httpRequest, cancellationToken).ConfigureAwait(false); HttpContext context = new HttpContext(httpRequest, response); if (this.HttpCallBack != null) { this.HttpCallBack.OnAfterHttpResponseEventHandler(this.GetClientInstance(), response); } if (response.StatusCode == 400) { throw new ErrorWithRequestException("If there is any issue with values passed in by the user", context); } if (response.StatusCode == 401) { throw new UnauthorizedRequestException("Authentication is either incorrect or not present", context); } if (response.StatusCode == 403) { throw new ForbiddenRequestException("The user is not authorized to access this resource", context); } if (response.StatusCode == 500) { throw new ErrorWithRequestException("An internal server error occurred", context); } // handle errors defined at the API level. this.ValidateResponse(response, context); var result = ApiHelper.JsonDeserialize <Models.TwoFactorVoiceResponse>(response.Body); ApiResponse <Models.TwoFactorVoiceResponse> apiResponse = new ApiResponse <Models.TwoFactorVoiceResponse>(response.StatusCode, response.Headers, result); return(apiResponse); }