From eee96bf8cfb1dd92515cf8f9909e2c6a3e6eea96 Mon Sep 17 00:00:00 2001 From: kspearrin Date: Fri, 21 Sep 2018 14:29:42 -0400 Subject: [PATCH] config flow --- .../CredentialProviderViewController.cs | 44 +++++++++++++++++-- src/iOS.Autofill/Info.plist | 7 ++- src/iOS.Autofill/Models/Context.cs | 3 +- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index db4ce1f7e..826ecafcf 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -143,16 +143,48 @@ namespace Bit.iOS.Autofill public override void PrepareInterfaceForExtensionConfiguration() { + System.Diagnostics.Debug.WriteLine("AUTOFILL BITWARDEN: PrepareInterfaceForExtensionConfiguration"); + _context.Configuring = true; + var authService = Resolver.Resolve(); - if(authService.IsAuthenticated) + if (!authService.IsAuthenticated) { - var task = ASHelpers.ReplaceAllIdentities(Resolver.Resolve()); + var alert = Dialogs.CreateAlert(null, AppResources.MustLogInMainApp, AppResources.Ok, (a) => + { + ExtensionContext.CompleteExtensionConfigurationRequest(); + }); + PresentViewController(alert, true, null); + return; + } + + var lockService = Resolver.Resolve(); + var lockType = lockService.GetLockTypeAsync(false).GetAwaiter().GetResult(); + switch (lockType) + { + case App.Enums.LockType.Fingerprint: + PerformSegue("lockFingerprintSegue", this); + break; + case App.Enums.LockType.PIN: + PerformSegue("lockPinSegue", this); + break; + case App.Enums.LockType.Password: + PerformSegue("lockPasswordSegue", this); + break; + default: + var task = ASHelpers.ReplaceAllIdentities(Resolver.Resolve()); + ExtensionContext.CompleteExtensionConfigurationRequest(); + break; } - ExtensionContext.CompleteExtensionConfigurationRequest(); } public void CompleteRequest(string username = null, string password = null, string totp = null) { + if(_context.Configuring) + { + ExtensionContext.CompleteExtensionConfigurationRequest(); + return; + } + if(string.IsNullOrWhiteSpace(username) && string.IsNullOrWhiteSpace(password)) { _googleAnalyticsService.TrackAutofillExtensionEvent("Canceled"); @@ -223,6 +255,12 @@ namespace Bit.iOS.Autofill ProvideCredential(); return; } + if(_context.Configuring) + { + var task = ASHelpers.ReplaceAllIdentities(Resolver.Resolve()); + ExtensionContext.CompleteExtensionConfigurationRequest(); + return; + } PerformSegue("loginListSegue", this); }); } diff --git a/src/iOS.Autofill/Info.plist b/src/iOS.Autofill/Info.plist index 7c064f56b..3a36508a4 100644 --- a/src/iOS.Autofill/Info.plist +++ b/src/iOS.Autofill/Info.plist @@ -22,8 +22,11 @@ MainInterface NSExtensionPointIdentifier com.apple.authentication-services-credential-provider-ui - ASCredentialProviderExtensionShowsConfigurationUI - + NSExtensionAttributes + + ASCredentialProviderExtensionShowsConfigurationUI + + UIDeviceFamily diff --git a/src/iOS.Autofill/Models/Context.cs b/src/iOS.Autofill/Models/Context.cs index c2abd1044..c4a6ccf2b 100644 --- a/src/iOS.Autofill/Models/Context.cs +++ b/src/iOS.Autofill/Models/Context.cs @@ -8,6 +8,7 @@ namespace Bit.iOS.Autofill.Models { public NSExtensionContext ExtContext { get; set; } public ASCredentialServiceIdentifier[] ServiceIdentifiers { get; set; } - public ASPasswordCredentialIdentity CredentialIdentity { get; set; } + public ASPasswordCredentialIdentity CredentialIdentity { get; set; } + public bool Configuring { get; set; } } }