예제 #1
0
        private async Task SignInAsync()
        {
            try
            {
                IEnumerable <IAccount> accounts = await App.PCA.GetAccountsAsync();

                AuthenticationResult silentAuthResult = await App.PCA.AcquireTokenSilent(AuthSettings.Scopes.Split(' '), accounts.FirstOrDefault()).ExecuteAsync();
            }
            catch (MsalUiRequiredException)
            {
                try
                {
                    AcquireTokenInteractiveParameterBuilder interactiveRequest = App.PCA.AcquireTokenInteractive(AuthSettings.Scopes.Split(' '));

                    if (App.AuthUIParent != null)
                    {
                        interactiveRequest = interactiveRequest.WithParentActivityOrWindow(App.AuthUIParent);
                    }
                    await interactiveRequest.ExecuteAsync();
                }
                catch (Exception ex)
                {
                    await App.Current.MainPage.DisplayAlert("Authentication failed", $"{ex.Message}", "Ok");
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Error", $"Authentication failed. See exception messsage for more details: {ex.Message}", "Ok");
            }

            await InitializeGraphClientAsync();
        }
        public static AcquireTokenInteractiveParameterBuilder WithUnoHelpers(this AcquireTokenInteractiveParameterBuilder builder)
        {
#if __WASM__
            builder.WithCustomWebUi(WasmWebUi.Instance);
#elif __MACOS__
            builder.WithParentActivityOrWindow(Windows.UI.Xaml.Window.Current.Content.Window);
#endif
            return(builder);
        }
        private async Task AcquireTokenSilentAsync()
        {
            try
            {
                Console.WriteLine("[TESTLOG] - start AcquireTokenSilentAsync");

                Console.WriteLine($"[TESTLOG] - PublicClientApplication? {_publicClientApplication == null}");

                AcquireTokenInteractiveParameterBuilder request = _publicClientApplication.AcquireTokenInteractive(new[] { "user.read" })
                                                                  .WithPrompt(Prompt.ForceLogin)
                                                                  .WithUseEmbeddedWebView(true);

                Console.WriteLine("[TESTLOG] - WithParentActivityOrWindow");
                Console.WriteLine($"[TESTLOG] - WithParentActivityOrWindow - root view controller {App.RootViewController}");

                request.WithParentActivityOrWindow(App.RootViewController);

                Console.WriteLine("[TESTLOG] - after creating request");
                AuthenticationResult result = await
                                              request.ExecuteAsync().ConfigureAwait(true);

                Console.WriteLine("[TESTLOG] - after executing interactive request");

                AcquireTokenSilentParameterBuilder builder = _publicClientApplication.AcquireTokenSilent(
                    App.s_scopes,
                    result.Account.Username);

                Console.WriteLine("[TESTLOG] - after creating silent request");

                AuthenticationResult res = await builder
                                           .WithForceRefresh(false)
                                           .ExecuteAsync()
                                           .ConfigureAwait(true);

                Console.WriteLine("[TESTLOG] - after executing silent request");


                var resText = GetResultDescription(res);

                if (res.AccessToken != null)
                {
                    acquireResponseTitleLabel.Text = SuccessfulResult;
                }

                acquireResponseLabel.Text = "Acquire Token Silent Acquisition Result....\n" + resText;
            }
            catch (Exception exception)
            {
                CreateExceptionMessage(exception);
            }
        }
예제 #4
0
        public static AcquireTokenInteractiveParameterBuilder WithUnoHelpers(this AcquireTokenInteractiveParameterBuilder builder)
        {
#if __WASM__
            builder.WithCustomWebUi(WasmWebUi.Instance);
#elif __MACOS__
#if NET6_0_OR_GREATER
            // WithUnoHelpers is not yet supported for macOS on .NET 6
            // builder.WithParentActivityOrWindow(Windows.UI.Xaml.Window.Current.Content.Window);
#else
            builder.WithParentActivityOrWindow(Windows.UI.Xaml.Window.Current.Content.Window);
#endif
#endif
            return(builder);
        }
예제 #5
0
 public void Build(AcquireTokenInteractiveParameterBuilder builder)
 {
     builder.WithParentActivityOrWindow(MainActivity.Current);
 }