public async Task <bool> Authenticate(int companyId, string username, string password, bool setToClose) { if (ApiUrl != null && ApiUrl.IsValid() && (Token == null || !Token.IsValid())) { try { Token = await ApiUrl.AppendPathSegment("token") .PostUrlEncodedAsync( new { companyId, username, password, setToClose, grant_type = "password" } ) .ReceiveJson <ApiTokenModel>(); Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me") .GetJsonAsync <EmployeeViewInfoModel>(); CompanyId = companyId; Username = username; Password = password; SetToClose = setToClose; return(true); } catch (FlurlHttpException) { } catch (Exception) { } } return(false); }
public async Task FinalizeSession() { if (Token?.AccessToken != null) { await ApiUrl.AppendPathSegment("ws/finalize-session") .WithOAuthBearerToken(Token.AccessToken) .GetAsync(); Token = null; CompanyId = 0; Username = String.Empty; Password = String.Empty; } }
public async Task <AuthenticationResponseModel> Authenticate(int companyId, string username, string password) { if (ApiUrl != null && ApiUrl.IsValid()) { try { var result = await ApiUrl.AppendPathSegment("token") .AllowAnyHttpStatus() .PostUrlEncodedAsync( new { companyId, username, password, grant_type = "password" } ) .HttpRequestResult <ApiTokenModel>(); if (result.IsSuccessStatusCode && result.Response != null) { Token = result.Response; Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me") .WithOAuthBearerToken(Token.AccessToken) .GetJsonAsync <EmployeeViewInfoModel>(); CompanyId = companyId; Username = username; Password = password; return(new AuthenticationResponseModel(true)); } else { return(new AuthenticationResponseModel(false, result.Error?.ErrorDescription)); } } catch (FlurlHttpException) { } catch (Exception) { } } return(new AuthenticationResponseModel(false)); }
private async Task Authenticate() { if (ApiUrl != null && ApiUrl.IsValid() && (Token == null || !Token.IsValid()) && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { Token = await ApiUrl.AppendPathSegment("token") .PostUrlEncodedAsync( new { CompanyId, Username, Password, grant_type = "password" } ) .ReceiveJson <ApiTokenModel>(); Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me") .WithOAuthBearerToken(Token.AccessToken) .GetJsonAsync <EmployeeViewInfoModel>(); } }