/// <summary> /// Call Login /// </summary> private async void SignInButton_Click(object sender, RoutedEventArgs e) { if (_clientApp != null) { var accounts = await _clientApp.GetAccountsAsync(); if (accounts.Any()) { try { await _clientApp.RemoveAsync(accounts.FirstOrDefault()); _clientApp = null; } catch (MsalException ex) { ResultText.Text = $"Error signing-out user: {ex.Message}"; } } } ComboBoxItem authority = Authority.SelectedItem as ComboBoxItem; _clientApp = PublicClientApplicationBuilder.Create(App.ClientId) .WithAuthority(AzureCloudInstance.AzurePublic, authority.Tag as String) .Build(); TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache); ComboBoxItem scopes = Scopes.SelectedItem as ComboBoxItem; var ScopesString = scopes.Tag as String; string[] scopesRequest = ScopesString.Split(' '); AuthAndCallAPI(null, scopesRequest); }
static App() { _clientApp = PublicClientApplicationBuilder.Create(ClientId) .WithAuthority($"{Instance}{Tenant}") .WithDefaultRedirectUri() .Build(); TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache); }
static App() { _clientApp = PublicClientApplicationBuilder.Create(ClientId) .WithAuthority(AzureCloudInstance.AzurePublic, Tenant) .Build(); TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache); }
static App() { PublicClientApp = PublicClientApplicationBuilder.Create(ClientId) .WithAuthority(AzureCloudInstance.AzurePublic, Tenant) .WithRedirectUri("urn:ietf:wg:oauth:2.0:oob") .WithDefaultRedirectUri() .Build(); TokenCacheHelper.EnableSerialization(PublicClientApp.UserTokenCache); }
static App() { var ClientId = Environment.GetEnvironmentVariable("AZ_ClientID"); var Tenant = Environment.GetEnvironmentVariable("AZ_TenantId"); _clientApp = PublicClientApplicationBuilder.Create(ClientId) .WithAuthority($"{Instance}{Tenant}") .WithDefaultRedirectUri() .Build(); TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache); }
/// <summary> /// Call Login /// </summary> private async void SignInButton_Click(object sender, RoutedEventArgs e) { if (_clientApp != null) { var accounts = await _clientApp.GetAccountsAsync(); if (accounts.Any()) { try { await _clientApp.RemoveAsync(accounts.FirstOrDefault()); _clientApp = null; } catch (MsalException msalex) { System.Diagnostics.Debug.WriteLine("Error Acquiring Token: " + msalex.Message); } } } ComboBoxItem authority = Authority.SelectedItem as ComboBoxItem; _clientApp = PublicClientApplicationBuilder.Create(App.ClientId) .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient") .WithAuthority(AzureCloudInstance.AzurePublic, authority.Tag as String) .WithClientCapabilities(new [] { "cp1" }) .Build(); TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache); ComboBoxItem scopes = Scopes.SelectedItem as ComboBoxItem; var ScopesString = scopes.Tag as String; string[] scopesRequest = ScopesString.Split(' '); ResultText.Text = await AuthAndCallAPI(null, scopesRequest); }