Пример #1
0
        public async Task WamInteractiveAuthNoWindowHandleAsync()
        {
            string[] scopes = new[]
            {
                "https://management.core.windows.net//.default"
            };

            IAccount accountToLogin = PublicClientApplication.OperatingSystemAccount;

            PublicClientApplicationBuilder pcaBuilder = PublicClientApplicationBuilder
                                                        .Create("04f0c124-f2bc-4f59-8241-bf6df9866bbd")
                                                        .WithAuthority("https://login.microsoftonline.com/organizations");

            IPublicClientApplication pca = pcaBuilder.WithBrokerPreview().Build();

            // Act
            try
            {
                var result = await pca.AcquireTokenInteractive(scopes)
                             .WithAccount(accountToLogin)
                             .ExecuteAsync()
                             .ConfigureAwait(false);
            }
            catch (MsalClientException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Public Client applications wanting to use WAM need to provide their window handle. " +
                                                  "Console applications can use GetConsoleWindow Windows API for this"));
            }
        }
Пример #2
0
        public async Task WamSilentAuthUserInteractionRequiredAsync()
        {
            string[] scopes = new[]
            {
                "https://management.core.windows.net//.default"
            };

            PublicClientApplicationBuilder pcaBuilder = PublicClientApplicationBuilder
                                                        .Create("04f0c124-f2bc-4f59-8241-bf6df9866bbd")
                                                        .WithAuthority("https://login.microsoftonline.com/organizations");

            IPublicClientApplication pca = pcaBuilder.WithBrokerPreview().Build();

            // Act
            try
            {
                var result = await pca.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount).ExecuteAsync().ConfigureAwait(false);
            }
            catch (MsalUiRequiredException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Need user interaction to continue"));
            }
        }
Пример #3
0
        public async Task WamSilentAuthLoginHintNoAccontInCacheAsync()
        {
            string[] scopes = new[]
            {
                "https://management.core.windows.net//.default"
            };

            PublicClientApplicationBuilder pcaBuilder = PublicClientApplicationBuilder
                                                        .Create("04f0c124-f2bc-4f59-8241-bf6df9866bbd")
                                                        .WithAuthority("https://login.microsoftonline.com/organizations");

            IPublicClientApplication pca = pcaBuilder.WithBrokerPreview().Build();

            // Act
            try
            {
                var result = await pca.AcquireTokenSilent(scopes, "idlab@").ExecuteAsync().ConfigureAwait(false);
            }
            catch (MsalUiRequiredException ex)
            {
                Assert.IsTrue(ex.Message.Contains("You are trying to acquire a token silently using a login hint. " +
                                                  "No account was found in the token cache having this login hint"));
            }
        }