コード例 #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);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: llamahats/csharp-wpf
 static App()
 {
     _clientApp = PublicClientApplicationBuilder.Create(ClientId)
                  .WithAuthority($"{Instance}{Tenant}")
                  .WithDefaultRedirectUri()
                  .Build();
     TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache);
 }
コード例 #3
0
        static App()
        {
            _clientApp = PublicClientApplicationBuilder.Create(ClientId)
                         .WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
                         .Build();

            TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache);
        }
コード例 #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);
 }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: urshree/MailChamp
        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);
        }
コード例 #6
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 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);
        }