From 4d8180a8c13b08f45a849c6735101d575579fbfb Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Wed, 15 Mar 2023 14:44:51 +0100 Subject: [PATCH] Replace the useWebauthnAsDefault option by a client side form toggle --- .../Auth/WebAuthnManageController.php | 1 - config/2fauth.php | 1 - ..._is_admin_and_preferences_to_users_table.php | 5 +++++ resources/js/mixins.js | 8 +++++++- resources/js/views/auth/Autolock.vue | 2 +- resources/js/views/auth/Login.vue | 17 +++++++++++++---- resources/js/views/settings/WebAuthn.vue | 5 ----- resources/lang/en/auth.php | 12 ++++-------- .../v1/Controllers/Auth/UserControllerTest.php | 2 -- tests/Feature/Http/SystemControllerTest.php | 1 - 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/Auth/WebAuthnManageController.php b/app/Http/Controllers/Auth/WebAuthnManageController.php index 200a0499..56901961 100644 --- a/app/Http/Controllers/Auth/WebAuthnManageController.php +++ b/app/Http/Controllers/Auth/WebAuthnManageController.php @@ -58,7 +58,6 @@ class WebAuthnManageController extends Controller // no more registered device exists. // See #110 if (blank($user->webAuthnCredentials()->WhereEnabled()->get())) { - Settings::delete('useWebauthnAsDefault'); Settings::delete('useWebauthnOnly'); Log::notice('No Webauthn credential enabled, Webauthn settings reset to default'); } diff --git a/config/2fauth.php b/config/2fauth.php index ab7ac77e..73415cd2 100644 --- a/config/2fauth.php +++ b/config/2fauth.php @@ -80,7 +80,6 @@ return [ 'defaultGroup' => 0, 'defaultCaptureMode' => 'livescan', 'useDirectCapture' => false, - 'useWebauthnAsDefault' => false, 'useWebauthnOnly' => false, 'getOfficialIcons' => true, 'theme' => 'system', diff --git a/database/migrations/2023_02_10_145413_add_is_admin_and_preferences_to_users_table.php b/database/migrations/2023_02_10_145413_add_is_admin_and_preferences_to_users_table.php index 48b63da3..12ff8a47 100644 --- a/database/migrations/2023_02_10_145413_add_is_admin_and_preferences_to_users_table.php +++ b/database/migrations/2023_02_10_145413_add_is_admin_and_preferences_to_users_table.php @@ -24,6 +24,11 @@ return new class extends Migration DB::table('users')->update(['is_admin' => 1]); + // The 'useWebauthnAsDefault' option is replaced by a local storage record + // so we delete it form the Options table to prevent its conversion to + // a user preference + DB::table('options')->where('key', 'useWebauthnAsDefault')->delete(); + // User options are converted as user preferences $options = DB::table('options')->get(); $preferences = config('2fauth.preferences'); diff --git a/resources/js/mixins.js b/resources/js/mixins.js index bdfbf160..07129bd8 100644 --- a/resources/js/mixins.js +++ b/resources/js/mixins.js @@ -20,11 +20,17 @@ Vue.mixin({ } else { await this.axios.get('/user/logout') - this.$storage.clear() + this.clearStorage() this.$router.push({ name: 'login', params: { forceRefresh: true } }) } }, + clearStorage() { + this.$storage.set('accounts') + this.$storage.set('groups') + this.$storage.set('lastRoute') + }, + exitSettings: function (event) { if (event) { this.$notify({ clean: true }) diff --git a/resources/js/views/auth/Autolock.vue b/resources/js/views/auth/Autolock.vue index 3daa08d2..1f226c3f 100644 --- a/resources/js/views/auth/Autolock.vue +++ b/resources/js/views/auth/Autolock.vue @@ -21,7 +21,7 @@ // there is nothing to do, we simply catch the error to avoid redondant navigation }); - this.$storage.clear() + this.clearStorage() }, } \ No newline at end of file diff --git a/resources/js/views/auth/Login.vue b/resources/js/views/auth/Login.vue index 8684b94a..3e82ebbe 100644 --- a/resources/js/views/auth/Login.vue +++ b/resources/js/views/auth/Login.vue @@ -12,7 +12,7 @@
@@ -28,7 +28,7 @@ @@ -53,17 +53,26 @@ password: '' }), isBusy: false, - showWebauthn: this.$root.userPreferences.useWebauthnAsDefault || this.$root.userPreferences.useWebauthnOnly, + showWebauthn: this.$root.userPreferences.useWebauthnOnly, csrfRefresher: null, webauthn: new WebAuthn() } }, mounted: function() { - this.csrfRefresher = setInterval(this.refreshToken, 300000); // 5 min + this.csrfRefresher = setInterval(this.refreshToken, 300000) // 5 min + this.showWebauthn = this.$storage.get('showWebauthnForm', false) }, methods : { + /** + * Toggle the form between legacy and webauthn method + */ + toggleForm() { + this.showWebauthn = ! this.showWebauthn + this.$storage.set('showWebauthnForm', this.showWebauthn) + }, + /** * Sign in using the login/password form */ diff --git a/resources/js/views/settings/WebAuthn.vue b/resources/js/views/settings/WebAuthn.vue index e03d7061..7201b8fd 100644 --- a/resources/js/views/settings/WebAuthn.vue +++ b/resources/js/views/settings/WebAuthn.vue @@ -42,8 +42,6 @@