mirror of
https://github.com/bitwarden/mobile.git
synced 2025-01-07 18:58:35 +01:00
PM-8051 Fix WebAuthenticator getting the Window properly on iOS with the workaround to use Share app window when coming from iOS extension (#3239)
This commit is contained in:
parent
b65f18d8e2
commit
8566f5c00a
@ -25,6 +25,7 @@ namespace Bit.App.Pages
|
|||||||
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>();
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>();
|
||||||
_vm = BindingContext as LoginPageViewModel;
|
_vm = BindingContext as LoginPageViewModel;
|
||||||
_vm.Page = this;
|
_vm.Page = this;
|
||||||
|
_vm.FromIosExtension = _appOptions?.IosExtension ?? false;
|
||||||
_vm.StartTwoFactorAction = () => MainThread.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
_vm.StartTwoFactorAction = () => MainThread.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
||||||
_vm.LogInSuccessAction = () => MainThread.BeginInvokeOnMainThread(async () => await LogInSuccessAsync());
|
_vm.LogInSuccessAction = () => MainThread.BeginInvokeOnMainThread(async () => await LogInSuccessAsync());
|
||||||
_vm.LogInWithDeviceAction = () => StartLoginWithDeviceAsync().FireAndForget();
|
_vm.LogInWithDeviceAction = () => StartLoginWithDeviceAsync().FireAndForget();
|
||||||
|
@ -19,6 +19,7 @@ namespace Bit.App.Pages
|
|||||||
_vm.Email = email;
|
_vm.Email = email;
|
||||||
_vm.AuthRequestType = authRequestType;
|
_vm.AuthRequestType = authRequestType;
|
||||||
_vm.AuthingWithSso = authingWithSso;
|
_vm.AuthingWithSso = authingWithSso;
|
||||||
|
_vm.FromIosExtension = _appOptions?.IosExtension ?? false;
|
||||||
_vm.StartTwoFactorAction = () => MainThread.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
_vm.StartTwoFactorAction = () => MainThread.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
||||||
_vm.LogInSuccessAction = () => MainThread.BeginInvokeOnMainThread(async () => await LogInSuccessAsync());
|
_vm.LogInSuccessAction = () => MainThread.BeginInvokeOnMainThread(async () => await LogInSuccessAsync());
|
||||||
_vm.UpdateTempPasswordAction = () => MainThread.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync());
|
_vm.UpdateTempPasswordAction = () => MainThread.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync());
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Bit.App.Pages
|
using Bit.App.Models;
|
||||||
|
|
||||||
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
public partial class RegisterPage : BaseContentPage
|
public partial class RegisterPage : BaseContentPage
|
||||||
{
|
{
|
||||||
@ -6,11 +8,12 @@
|
|||||||
|
|
||||||
private bool _inputFocused;
|
private bool _inputFocused;
|
||||||
|
|
||||||
public RegisterPage(HomePage homePage)
|
public RegisterPage(HomePage homePage, AppOptions appOptions = null)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_vm = BindingContext as RegisterPageViewModel;
|
_vm = BindingContext as RegisterPageViewModel;
|
||||||
_vm.Page = this;
|
_vm.Page = this;
|
||||||
|
_vm.FromIosExtension = appOptions?.IosExtension ?? false;
|
||||||
_vm.RegistrationSuccess = () => MainThread.BeginInvokeOnMainThread(async () => await RegistrationSuccessAsync(homePage));
|
_vm.RegistrationSuccess = () => MainThread.BeginInvokeOnMainThread(async () => await RegistrationSuccessAsync(homePage));
|
||||||
_vm.CloseAction = async () =>
|
_vm.CloseAction = async () =>
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,7 @@ namespace Bit.App.Pages
|
|||||||
_vm = BindingContext as TwoFactorPageViewModel;
|
_vm = BindingContext as TwoFactorPageViewModel;
|
||||||
_vm.Page = this;
|
_vm.Page = this;
|
||||||
_vm.AuthingWithSso = authingWithSso ?? false;
|
_vm.AuthingWithSso = authingWithSso ?? false;
|
||||||
|
_vm.FromIosExtension = _appOptions?.IosExtension ?? false;
|
||||||
_vm.StartSetPasswordAction = () =>
|
_vm.StartSetPasswordAction = () =>
|
||||||
MainThread.BeginInvokeOnMainThread(async () => await StartSetPasswordAsync());
|
MainThread.BeginInvokeOnMainThread(async () => await StartSetPasswordAsync());
|
||||||
_vm.TwoFactorAuthSuccessAction = () =>
|
_vm.TwoFactorAuthSuccessAction = () =>
|
||||||
|
@ -11,6 +11,13 @@ using Bit.Core.Models.Request;
|
|||||||
using Bit.Core.Resources.Localization;
|
using Bit.Core.Resources.Localization;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Bit.Core.Services;
|
||||||
|
|
||||||
|
#if IOS
|
||||||
|
using WebAuthenticator = Bit.Core.Utilities.MAUI.WebAuthenticator;
|
||||||
|
using WebAuthenticatorResult = Bit.Core.Utilities.MAUI.WebAuthenticatorResult;
|
||||||
|
using WebAuthenticatorOptions = Bit.Core.Utilities.MAUI.WebAuthenticatorOptions;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
@ -136,6 +143,7 @@ namespace Bit.App.Pages
|
|||||||
nameof(ShowTryAgain),
|
nameof(ShowTryAgain),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand SubmitCommand { get; }
|
public ICommand SubmitCommand { get; }
|
||||||
public ICommand MoreCommand { get; }
|
public ICommand MoreCommand { get; }
|
||||||
public ICommand AuthenticateWithDuoFramelessCommand { get; }
|
public ICommand AuthenticateWithDuoFramelessCommand { get; }
|
||||||
@ -261,7 +269,11 @@ namespace Bit.App.Pages
|
|||||||
authResult = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
|
authResult = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
|
||||||
{
|
{
|
||||||
Url = new Uri(url),
|
Url = new Uri(url),
|
||||||
CallbackUrl = new Uri(Constants.DuoCallback)
|
CallbackUrl = new Uri(Constants.DuoCallback),
|
||||||
|
#if IOS
|
||||||
|
ShouldUseSharedApplicationKeyWindow = FromIosExtension
|
||||||
|
#endif
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
@ -348,6 +360,9 @@ namespace Bit.App.Pages
|
|||||||
Url = new Uri(url),
|
Url = new Uri(url),
|
||||||
CallbackUrl = new Uri(callbackUri),
|
CallbackUrl = new Uri(callbackUri),
|
||||||
PrefersEphemeralWebBrowserSession = true,
|
PrefersEphemeralWebBrowserSession = true,
|
||||||
|
#if IOS
|
||||||
|
ShouldUseSharedApplicationKeyWindow = FromIosExtension
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
authResult = await WebAuthenticator.AuthenticateAsync(options);
|
authResult = await WebAuthenticator.AuthenticateAsync(options);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,12 @@ using Bit.App.Utilities;
|
|||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
using Microsoft.Maui.Authentication;
|
using Microsoft.Maui.Authentication;
|
||||||
|
|
||||||
|
#if IOS
|
||||||
|
using WebAuthenticator = Bit.Core.Utilities.MAUI.WebAuthenticator;
|
||||||
|
using WebAuthenticatorResult = Bit.Core.Utilities.MAUI.WebAuthenticatorResult;
|
||||||
|
using WebAuthenticatorOptions = Bit.Core.Utilities.MAUI.WebAuthenticatorOptions;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
public abstract class CaptchaProtectedViewModel : BaseViewModel
|
public abstract class CaptchaProtectedViewModel : BaseViewModel
|
||||||
@ -16,6 +22,8 @@ namespace Bit.App.Pages
|
|||||||
protected abstract IPlatformUtilsService platformUtilsService { get; }
|
protected abstract IPlatformUtilsService platformUtilsService { get; }
|
||||||
protected string _captchaToken = null;
|
protected string _captchaToken = null;
|
||||||
|
|
||||||
|
public bool FromIosExtension { get; set; }
|
||||||
|
|
||||||
protected async Task<bool> HandleCaptchaAsync(string captchaSiteKey, bool needsCaptcha, Func<Task> onSuccess)
|
protected async Task<bool> HandleCaptchaAsync(string captchaSiteKey, bool needsCaptcha, Func<Task> onSuccess)
|
||||||
{
|
{
|
||||||
if (!needsCaptcha)
|
if (!needsCaptcha)
|
||||||
@ -61,6 +69,9 @@ namespace Bit.App.Pages
|
|||||||
Url = new Uri(url),
|
Url = new Uri(url),
|
||||||
CallbackUrl = new Uri(callbackUri),
|
CallbackUrl = new Uri(callbackUri),
|
||||||
PrefersEphemeralWebBrowserSession = false,
|
PrefersEphemeralWebBrowserSession = false,
|
||||||
|
#if IOS
|
||||||
|
ShouldUseSharedApplicationKeyWindow = FromIosExtension
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
authResult = await WebAuthenticator.AuthenticateAsync(options);
|
authResult = await WebAuthenticator.AuthenticateAsync(options);
|
||||||
}
|
}
|
||||||
|
@ -617,8 +617,9 @@ namespace Bit.iOS.Autofill
|
|||||||
|
|
||||||
private void LaunchRegisterFlow()
|
private void LaunchRegisterFlow()
|
||||||
{
|
{
|
||||||
var registerPage = new RegisterPage(null);
|
var appOptions = new AppOptions { IosExtension = true };
|
||||||
var app = new App.App(new AppOptions { IosExtension = true });
|
var registerPage = new RegisterPage(null, appOptions);
|
||||||
|
var app = new App.App(appOptions);
|
||||||
ThemeManager.SetTheme(app.Resources);
|
ThemeManager.SetTheme(app.Resources);
|
||||||
ThemeManager.ApplyResourcesTo(registerPage);
|
ThemeManager.ApplyResourcesTo(registerPage);
|
||||||
if (registerPage.BindingContext is RegisterPageViewModel vm)
|
if (registerPage.BindingContext is RegisterPageViewModel vm)
|
||||||
@ -696,8 +697,9 @@ namespace Bit.iOS.Autofill
|
|||||||
|
|
||||||
private void LaunchTwoFactorFlow(bool authingWithSso)
|
private void LaunchTwoFactorFlow(bool authingWithSso)
|
||||||
{
|
{
|
||||||
var twoFactorPage = new TwoFactorPage(authingWithSso);
|
var appOptions = new AppOptions { IosExtension = true };
|
||||||
var app = new App.App(new AppOptions { IosExtension = true });
|
var twoFactorPage = new TwoFactorPage(authingWithSso, appOptions);
|
||||||
|
var app = new App.App();
|
||||||
ThemeManager.SetTheme(app.Resources);
|
ThemeManager.SetTheme(app.Resources);
|
||||||
ThemeManager.ApplyResourcesTo(twoFactorPage);
|
ThemeManager.ApplyResourcesTo(twoFactorPage);
|
||||||
if (twoFactorPage.BindingContext is TwoFactorPageViewModel vm)
|
if (twoFactorPage.BindingContext is TwoFactorPageViewModel vm)
|
||||||
|
Loading…
Reference in New Issue
Block a user