From 7ffad66b0b43a0e42893167d275efb55347da2c5 Mon Sep 17 00:00:00 2001 From: prajnamohan1 <36304276+prajnamohan1@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:22:03 +0100 Subject: [PATCH] Fixed Oauth redirect not working on Android Chrome (#18513) * Fixed Oauth redirect not working on Android Chrome This fixes the issue described in https://github.com/hashicorp/vault/issues/16778. Navigation is blocked in Android chrome while redirecting back after OIDC authentication. The issue is explained by the lead maintainer of AppAuth(https://stackoverflow.com/a/41882732). The latest Chrome version redirects to the app only if triggered by the user and not automatically redirect. Hence, a link is added in the UI to redirect back to the app. * Update ui/app/templates/vault/cluster/oidc-provider.hbs Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> * added requested changes * Modified requested changes and added changelog * Added requested change * Modified requested changes --------- Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> --- changelog/18513.txt | 3 +++ ui/app/routes/vault/cluster/oidc-provider.js | 12 ++++++------ ui/app/templates/vault/cluster/oidc-provider.hbs | 4 +++- ui/tests/acceptance/oidc-provider-test.js | 9 ++++++--- 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 changelog/18513.txt diff --git a/changelog/18513.txt b/changelog/18513.txt new file mode 100644 index 0000000000..6b3ca2fe48 --- /dev/null +++ b/changelog/18513.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: latest version of chrome does not automatically redirect back to the app after authentication unless triggered by the user, hence added a link to redirect back to the app. +``` \ No newline at end of file diff --git a/ui/app/routes/vault/cluster/oidc-provider.js b/ui/app/routes/vault/cluster/oidc-provider.js index d969c1e68e..a33a9b6ac6 100644 --- a/ui/app/routes/vault/cluster/oidc-provider.js +++ b/ui/app/routes/vault/cluster/oidc-provider.js @@ -94,17 +94,17 @@ export default class VaultClusterOidcProviderRoute extends Route { _handleSuccess(response, baseUrl, state) { const { code } = response; const redirectUrl = this._buildUrl(baseUrl, { code, state }); - if (Ember.testing) { - return { redirectUrl }; + if (!Ember.testing) { + this.win.location.replace(redirectUrl); } - this.win.location.replace(redirectUrl); + return { redirectUrl }; } _handleError(errorResp, baseUrl) { const redirectUrl = this._buildUrl(baseUrl, { ...errorResp }); - if (Ember.testing) { - return { redirectUrl }; + if (!Ember.testing) { + this.win.location.replace(redirectUrl); } - this.win.location.replace(redirectUrl); + return { redirectUrl }; } /** diff --git a/ui/app/templates/vault/cluster/oidc-provider.hbs b/ui/app/templates/vault/cluster/oidc-provider.hbs index 24f57426bd..e3fcd541a8 100644 --- a/ui/app/templates/vault/cluster/oidc-provider.hbs +++ b/ui/app/templates/vault/cluster/oidc-provider.hbs @@ -22,7 +22,9 @@ @onSuccess={{this._handleSuccess}} /> {{else if this.model.redirectUrl}} -
{{this.model.redirectUrl}}
+ +

If you are not automatically redirected, + click here to go back to app.

{{else}} {{/if}} diff --git a/ui/tests/acceptance/oidc-provider-test.js b/ui/tests/acceptance/oidc-provider-test.js index 8ef24aa24c..4446afccd9 100644 --- a/ui/tests/acceptance/oidc-provider-test.js +++ b/ui/tests/acceptance/oidc-provider-test.js @@ -163,10 +163,11 @@ module('Acceptance | oidc provider', function (hooks) { await authFormComponent.login(); await settled(); assert.strictEqual(currentURL(), url, 'URL is as expected after login'); - assert.dom('[data-test-oidc-redirect]').exists('redirect text exists'); assert .dom('[data-test-oidc-redirect]') - .hasTextContaining(`${callback}?code=`, 'Successful redirect to callback'); + .hasTextContaining(`click here to go back to app`, 'Shows link back to app'); + const link = document.querySelector('[data-test-oidc-redirect]').getAttribute('href'); + assert.ok(link.includes('/callback?code='), 'Redirects to correct url'); //* clean up test state await clearRecord(this.store, 'oidc/client', 'my-webapp'); @@ -191,7 +192,9 @@ module('Acceptance | oidc provider', function (hooks) { await settled(); assert .dom('[data-test-oidc-redirect]') - .hasTextContaining(`${callback}?code=`, 'Successful redirect to callback'); + .hasTextContaining(`click here to go back to app`, 'Shows link back to app'); + const link = document.querySelector('[data-test-oidc-redirect]').getAttribute('href'); + assert.ok(link.includes('/callback?code='), 'Redirects to correct url'); //* clean up test state await clearRecord(this.store, 'oidc/client', 'my-webapp');