mirror of
https://github.com/bitwarden/mobile.git
synced 2024-06-26 10:36:21 +02:00
* initial commit - add UsesKeyConnector to UserService - add models - begin work on authentication * finish auth workflow for key connector sso login - finish api call for get user key - start api calls for posts to key connector * Bypass lock page if already unlocked * Move logic to KeyConnectorService, log out if no pin or biometric is set * Disable password reprompt when using key connector * hide password reprompt checkbox when editing or adding cipher * add PostUserKey and PostSetKeyConnector calls * add ConvertMasterPasswordPage * add functionality to RemoveMasterPasswordPage - rename Convert to Remove * Hide Change Master Password button if using key connector * Add OTP verification for export component * Update src/App/Pages/Vault/AddEditPage.xaml.cs Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * remove toolbar item "close" * Update src/Core/Models/Request/KeyConnectorUserKeyRequest.cs Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * remove new line in resource string - format warning as two labels - set label in code behind for loading simultaneously * implement GetAndSetKey in KeyConnectorService - ignore EnvironmentService call * remove unnecesary orgIdentifier * move RemoveMasterPasswordPage call to LockPage * add spacing to export vault page * log out if no PIN or bio on lock page with key connector * Delete excessive whitespace * Delete excessive whitespace * Change capitalisation of OTP * add default value to models for backwards compatibility * remove this keyword * actually handle exceptions * move RemoveMasterPasswordPage to TabPage using messaging service * add minor improvements * remove 'this.' Co-authored-by: Hinton <oscar@oscarhinton.com> Co-authored-by: Thomas Rittson <trittson@bitwarden.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
130 lines
4.4 KiB
C#
130 lines
4.4 KiB
C#
using Bit.App.Models;
|
|
using Bit.Core.Abstractions;
|
|
using Bit.Core.Utilities;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Bit.App.Utilities;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Bit.App.Pages
|
|
{
|
|
public partial class LoginSsoPage : BaseContentPage
|
|
{
|
|
private readonly IStorageService _storageService;
|
|
private readonly IMessagingService _messagingService;
|
|
private readonly IVaultTimeoutService _vaultTimeoutService;
|
|
private readonly LoginSsoPageViewModel _vm;
|
|
private readonly AppOptions _appOptions;
|
|
|
|
private AppOptions _appOptionsCopy;
|
|
|
|
public LoginSsoPage(AppOptions appOptions = null)
|
|
{
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
|
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
|
_messagingService.Send("showStatusBar", true);
|
|
_appOptions = appOptions;
|
|
InitializeComponent();
|
|
_vm = BindingContext as LoginSsoPageViewModel;
|
|
_vm.Page = this;
|
|
_vm.StartTwoFactorAction = () => Device.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
|
_vm.StartSetPasswordAction = () =>
|
|
Device.BeginInvokeOnMainThread(async () => await StartSetPasswordAsync());
|
|
_vm.SsoAuthSuccessAction = () => Device.BeginInvokeOnMainThread(async () => await SsoAuthSuccessAsync());
|
|
_vm.UpdateTempPasswordAction =
|
|
() => Device.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync());
|
|
_vm.CloseAction = async () =>
|
|
{
|
|
_messagingService.Send("showStatusBar", false);
|
|
await Navigation.PopModalAsync();
|
|
};
|
|
if (Device.RuntimePlatform == Device.Android)
|
|
{
|
|
ToolbarItems.RemoveAt(0);
|
|
}
|
|
}
|
|
|
|
protected override async void OnAppearing()
|
|
{
|
|
base.OnAppearing();
|
|
await _vm.InitAsync();
|
|
if (string.IsNullOrWhiteSpace(_vm.OrgIdentifier))
|
|
{
|
|
RequestFocus(_orgIdentifier);
|
|
}
|
|
}
|
|
|
|
private void CopyAppOptions()
|
|
{
|
|
if (_appOptions != null)
|
|
{
|
|
// create an object copy of _appOptions to persist values when app is exited during web auth flow
|
|
_appOptionsCopy = new AppOptions();
|
|
_appOptionsCopy.SetAllFrom(_appOptions);
|
|
}
|
|
}
|
|
|
|
private void RestoreAppOptionsFromCopy()
|
|
{
|
|
if (_appOptions != null)
|
|
{
|
|
// restore values to original readonly _appOptions object from copy
|
|
_appOptions.SetAllFrom(_appOptionsCopy);
|
|
_appOptionsCopy = null;
|
|
}
|
|
}
|
|
|
|
private async void LogIn_Clicked(object sender, EventArgs e)
|
|
{
|
|
if (DoOnce())
|
|
{
|
|
CopyAppOptions();
|
|
await _vm.LogInAsync();
|
|
}
|
|
}
|
|
|
|
private void Close_Clicked(object sender, EventArgs e)
|
|
{
|
|
if (DoOnce())
|
|
{
|
|
_vm.CloseAction();
|
|
}
|
|
}
|
|
|
|
private async Task StartTwoFactorAsync()
|
|
{
|
|
RestoreAppOptionsFromCopy();
|
|
var page = new TwoFactorPage(true, _appOptions, _vm.OrgIdentifier);
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
}
|
|
|
|
private async Task StartSetPasswordAsync()
|
|
{
|
|
RestoreAppOptionsFromCopy();
|
|
var page = new SetPasswordPage(_appOptions, _vm.OrgIdentifier);
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
}
|
|
|
|
private async Task UpdateTempPasswordAsync()
|
|
{
|
|
var page = new UpdateTempPasswordPage();
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
}
|
|
|
|
private async Task SsoAuthSuccessAsync()
|
|
{
|
|
RestoreAppOptionsFromCopy();
|
|
await AppHelpers.ClearPreviousPage();
|
|
if (await _vaultTimeoutService.IsLockedAsync())
|
|
{
|
|
Application.Current.MainPage = new NavigationPage(new LockPage(_appOptions));
|
|
}
|
|
else
|
|
{
|
|
Application.Current.MainPage = new TabsPage(_appOptions, null);
|
|
}
|
|
}
|
|
}
|
|
}
|