Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 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);
        }
Exemplo n.º 4
0
 static App()
 {
     PublicClientApp = PublicClientApplicationBuilder.Create(ClientId)
                       .WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
                       .WithRedirectUri("urn:ietf:wg:oauth:2.0:oob")
                       .WithDefaultRedirectUri()
                       .Build();
     TokenCacheHelper.EnableSerialization(PublicClientApp.UserTokenCache);
 }
Exemplo n.º 5
0
        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);
        }
        static App()
        {
            string authority = $"https://login.microsoftonline.com/{Tenant}";

            _clientApp = new PublicClientApplication(ClientId, authority, TokenCacheHelper.GetUserCache());
        }
Exemplo n.º 8
0
 static App()
 {
     _clientApp = new PublicClientApplication(ClientId, "https://login.microsoftonline.com/common", TokenCacheHelper.GetUserCache());
 }
 static App()
 {
     // the common endpoint (supports AAD and MSA) doesn't permit integrated auth
     // you must use either a tenant (domain or GUID) or the AAD generic endpoint (organizations)
     //_clientApp = new PublicClientApplication(ClientId, "https://login.microsoftonline.com/common", TokenCacheHelper.GetUserCache());
     _clientApp = new PublicClientApplication(ClientId, "https://login.microsoftonline.com/organizations", TokenCacheHelper.GetUserCache());
 }
Exemplo n.º 10
0
 static App()
 {
     _clientApp = new PublicClientApplication(ClientId, ConfigurationSettings.AppSettings["authority"], TokenCacheHelper.GetUserCache());
 }