Beautiful Open-Source Form Builder
fix: prevent OIDC restart during account linking (#1224)
Julien Nahuma96c082ec5b9
diff --git a/api/tests/Feature/Enterprise/Oidc/OidcLinkControllerTest.php b/api/tests/Feature/Enterprise/Oidc/OidcLinkControllerTest.phpindex d303afaff..01c0e035d 100644--- a/api/tests/Feature/Enterprise/Oidc/OidcLinkControllerTest.php+++ b/api/tests/Feature/Enterprise/Oidc/OidcLinkControllerTest.php@@ -14,6 +14,43 @@ afterEach(function () {});describe('OidcLinkController', function () {+ it('completes an account link after the one-time password login allowed by forced OIDC', function () {+ $connection = IdentityConnection::factory()->create([+ 'enabled' => true,+ 'type' => IdentityConnection::TYPE_OIDC,+ ]);+ $user = $this->createUser();+ $linkToken = app(OidcLinkService::class)->createLinkToken(+ connectionId: $connection->id,+ subject: 'existing-account-subject',+ email: $user->email,+ claims: ['email' => $user->email],+ );+ config(['oidc.force_login' => true]);++ $loginResponse = $this->postJson('/login', [+ 'email' => $user->email,+ 'password' => 'Abcd@1234',+ 'oidc_link_token' => $linkToken,+ ])->assertSuccessful();++ $this->withToken($loginResponse->json('token'))+ ->postJson('/auth/oidc/link', [+ 'link_token' => $linkToken,+ ])+ ->assertSuccessful()+ ->assertJson(['linked' => true]);++ $this->assertDatabaseHas('user_identities', [+ 'user_id' => $user->id,+ 'connection_id' => $connection->id,+ 'subject' => 'existing-account-subject',+ 'email' => $user->email,+ ]);++ config(['oidc.force_login' => false]);+ });+it('links an existing account with a valid token', function () {$user = $this->actingAsUser();$connection = IdentityConnection::factory()->create();diff --git a/client/components/pages/auth/components/LoginForm.vue b/client/components/pages/auth/components/LoginForm.vueindex e82dba996..b2236f3fb 100644--- a/client/components/pages/auth/components/LoginForm.vue+++ b/client/components/pages/auth/components/LoginForm.vue@@ -257,7 +257,7 @@ onBeforeUnmount(() => {// Methodsconst checkOidcOptions = async () => {- if (!oidcAvailable.value || !form.email || form.busy || isOidcRateLimited.value) {+ if (isLinkingExistingAccount.value || !oidcAvailable.value || !form.email || form.busy || isOidcRateLimited.value) {return}diff --git a/client/test/nuxt/oidc-link-flow.spec.ts b/client/test/nuxt/oidc-link-flow.spec.tsindex eae91ce68..a0a02ecc6 100644--- a/client/test/nuxt/oidc-link-flow.spec.ts+++ b/client/test/nuxt/oidc-link-flow.spec.ts@@ -535,4 +535,50 @@ describe('OIDC link flow', () => {expect(vm.form.oidc_link_token).toBe('link-token-123')expect(vm.form.mutate).toHaveBeenCalledOnce()})++ it('does not restart OIDC when the email field loses focus during account linking', async () => {+ linkTokenValue.value = 'link-token-123'+ setupGlobals({}, {+ featureFlags: {+ 'oidc.available': true,+ 'oidc.forced': true,+ },+ })++ const wrapper = mount(LoginForm, {+ global: {+ stubs: {+ ForgotPasswordModal: true,+ TwoFactorVerificationModal: true,+ VForm: {+ template: '<form><slot /></form>',+ props: ['form'],+ },+ TextInput: {+ template: '<input :name="name" @blur="$emit(\'blur\')" />',+ props: ['name'],+ emits: ['blur'],+ },+ CheckboxInput: true,+ UAlert: true,+ UButton: true,+ VTransition: {+ template: '<div><slot /></div>',+ },+ NuxtLink: true,+ ClientOnly: true,+ GoogleOneTap: true,+ },+ },+ })++ const vm = wrapper.vm as any+ vm.form.email = '[email protected]'+ vm.form.post = vi.fn(() => Promise.resolve({ action: 'none' }))++ await wrapper.find('input[name="email"]').trigger('blur')+ await flushPromises()++ expect(vm.form.post).not.toHaveBeenCalled()+ })})