public async Task <IMsalResult> LoginAsync(string policy)
        {
            try
            {
                var result = await SilentLoginAsync(policy);

                if (result.Success)
                {
                    return(result);
                }

                var builder = AuthClient.AcquireTokenInteractive(Config.Scopes)
#if __ANDROID__
                              .WithParentActivityOrWindow(Xamarin.Essentials.Platform.CurrentActivity)
#endif

                              .WithUseEmbeddedWebView(true);
                if (Config.IsB2C)
                {
                    builder = builder.WithB2CAuthority(Config.GetB2CAuthority(policy));
                }

                var authResult = await builder.ExecuteAsync();

                _authResult.OnNext(authResult);
                _accessToken.OnNext(authResult.AccessToken);
                return(new MsalResult(authResult));
            }
            catch (Exception ex)
            {
                return(new MsalResult(ex));
            }
        }
        private async Task <AuthenticationResult> AcquireTokenInteractive(string policy)
        {
            IEnumerable <IAccount> accounts = await AuthClient.GetAccountsAsync();

            var account = GetAccountByPolicy(accounts, policy);
            var builder = AuthClient.AcquireTokenInteractive(Config.Scopes)
                          .WithAccount(account)
#if __ANDROID__
                          .WithParentActivityOrWindow(Xamarin.Essentials.Platform.CurrentActivity)
#endif

                          .WithUseEmbeddedWebView(true)
                          .WithAuthority(Config.GetB2CAuthority(policy));

            return(await builder.ExecuteAsync());
        }
        public async Task <AuthenticationResult> LoginAsync(string policy)
        {
            AuthenticationResult result;

            try
            {
                result = await SilentLoginAsync(policy);

                if (result != null)
                {
                    return(result);
                }

                result = await AuthClient.AcquireTokenInteractive(Options.Scopes)
                         .WithB2CAuthority(Options.GetB2CAuthority(policy))
                         .WithUseEmbeddedWebView(true)
#if __ANDROID__
                         .WithParentActivityOrWindow(CurrentActivity.Activity)
#endif
                         .ExecuteAsync();
            }
            catch (MsalException msal)
            {
                if (msal.ErrorCode != MsalError.AuthenticationCanceledError && msal.ErrorCode != MsalError.PasswordRequiredForManagedUserError)
                {
                    LogException(msal, "LoginAsync", policy);
                }

                throw;
            }
            catch (Exception ex)
            {
                LogException(ex, "LoginAsync", policy);
                throw;
            }

            return(result);
        }