private static bool AuthenticateUser() { lock (_sync) { BearerToken = null; if (string.IsNullOrEmpty(Username)) { throw new AuthenticationException("Username must be provided!"); } if (string.IsNullOrEmpty(Password)) { throw new AuthenticationException("Password must be provided!"); } try { var controller = new AuthorizationApi(); var request = new PasswordAuthRequest(Username, Password); var response = controller.Token(request); BearerToken = response.Token; Console.WriteLine("Authenticated!"); } catch (Exception e) { Console.WriteLine("Failed to authenticate!"); Console.WriteLine(e); throw e; } } return(true); }
/// <summary> /// /// </summary> /// <exception cref="LoanStreet.LoanServicing.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordAuthRequest"> (optional)</param> /// <returns>Task of ApiResponse (PasswordAuthResponse)</returns> public async System.Threading.Tasks.Task <LoanStreet.LoanServicing.Client.ApiResponse <PasswordAuthResponse> > TokenAsyncWithHttpInfo(PasswordAuthRequest passwordAuthRequest = default(PasswordAuthRequest)) { LoanStreet.LoanServicing.Client.RequestOptions localVarRequestOptions = new LoanStreet.LoanServicing.Client.RequestOptions(); String[] _contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] _accepts = new String[] { "application/json" }; foreach (var _contentType in _contentTypes) { localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType); } foreach (var _accept in _accepts) { localVarRequestOptions.HeaderParameters.Add("Accept", _accept); } localVarRequestOptions.Data = passwordAuthRequest; // make the HTTP request var localVarResponse = await this.AsynchronousClient.PostAsync <PasswordAuthResponse>("/v1/public/token", localVarRequestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("Token", localVarResponse); if (_exception != null) { throw _exception; } } return(localVarResponse); }
/// <summary> /// /// </summary> /// <exception cref="LoanStreet.LoanServicing.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordAuthRequest"> (optional)</param> /// <returns>Task of PasswordAuthResponse</returns> public async System.Threading.Tasks.Task <PasswordAuthResponse> TokenAsync(PasswordAuthRequest passwordAuthRequest = default(PasswordAuthRequest)) { LoanStreet.LoanServicing.Client.ApiResponse <PasswordAuthResponse> localVarResponse = await TokenAsyncWithHttpInfo(passwordAuthRequest); return(localVarResponse.Data); }
/// <summary> /// /// </summary> /// <exception cref="LoanStreet.LoanServicing.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordAuthRequest"> (optional)</param> /// <returns>ApiResponse of PasswordAuthResponse</returns> public LoanStreet.LoanServicing.Client.ApiResponse <PasswordAuthResponse> TokenWithHttpInfo(PasswordAuthRequest passwordAuthRequest = default(PasswordAuthRequest)) { LoanStreet.LoanServicing.Client.RequestOptions localVarRequestOptions = new LoanStreet.LoanServicing.Client.RequestOptions(); String[] _contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] _accepts = new String[] { "application/json" }; var localVarContentType = LoanStreet.LoanServicing.Client.ClientUtils.SelectHeaderContentType(_contentTypes); if (localVarContentType != null) { localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = LoanStreet.LoanServicing.Client.ClientUtils.SelectHeaderAccept(_accepts); if (localVarAccept != null) { localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); } localVarRequestOptions.Data = passwordAuthRequest; // make the HTTP request var localVarResponse = this.Client.Post <PasswordAuthResponse>("/v1/public/token", localVarRequestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("Token", localVarResponse); if (_exception != null) { throw _exception; } } return(localVarResponse); }
/// <summary> /// /// </summary> /// <exception cref="LoanStreet.LoanServicing.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordAuthRequest"> (optional)</param> /// <returns>PasswordAuthResponse</returns> public PasswordAuthResponse Token(PasswordAuthRequest passwordAuthRequest = default(PasswordAuthRequest)) { LoanStreet.LoanServicing.Client.ApiResponse <PasswordAuthResponse> localVarResponse = TokenWithHttpInfo(passwordAuthRequest); return(localVarResponse.Data); }