/// <summary> /// Generate D365 HTTP Client. /// </summary> /// <returns>HTTP Client.</returns> private static async Task <HttpClient> GenerateD365HttpClient() { var client = new HttpClient(); client.BaseAddress = new Uri(Settings.D365URL + "/data/"); var authHeader = await D365AuthHelper.GetAuthorizationHeader(); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authHeader); return(client); }
public CustomerListPage() { InitializeComponent(); BindingContext = VM = new CustomerListViewModel(); // handle auth login/logout var tbLoginOut = ToolbarHelper.GenerateToolbarButton("Auth", new Command(async() => { if (Settings.AzureADUserInfo != null) { // logout new AuthenticationContext(Settings.AzureADAuthority).TokenCache.Clear(); DependencyService.Get <IAuthenticator>().ClearCookies(); VM.CustomerList.Clear(); Settings.AzureADUserInfo = null; await ToastHelper.Success("Logged Out!"); } else { // login try { await D365AuthHelper.GetAuthorizationHeader(); } catch (Exception ex) { await DisplayAlert("Authentication Error", ex.Message, "Ok"); return; } await VM.ExecuteLoadCustomersCommand(); await ToastHelper.Success("Customers Loaded!"); } })); ToolbarItems.Add(tbLoginOut); }