From f7f1041daab317afcebee79caf0743b4b39ad641 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:56:32 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20oidc=20retry=20not=20work?= =?UTF-8?q?ing=20for=20secure=20links=20in=20desktop=20ui=20(#2641)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 oidc retry not working for secure links in desktop ui --- .../scopes/scope/authenticate/method/oidc.js | 25 ++++++++++++++----- .../scopes/scope/authenticate/method/oidc.js | 10 ++++++++ .../scopes/scope/authenticate/method/oidc.hbs | 2 +- .../scopes/scope/authenticate/method/oidc.js | 25 ++++++++++++++----- .../scopes/scope/authenticate/method/oidc.js | 10 ++++++++ .../scopes/scope/authenticate/method/oidc.hbs | 2 +- 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js b/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js index c64b230c3..ad55293da 100644 --- a/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js +++ b/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js @@ -3,21 +3,34 @@ * SPDX-License-Identifier: BUSL-1.1 */ -import Controller from '@ember/controller'; +import Controller, { inject as controller } from '@ember/controller'; import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; export default class ScopesScopeAuthenticateMethodOidcController extends Controller { + @controller('scopes/scope/authenticate/method/index') authenticateMethod; + // =services @service session; - // =attributes + // =actions /** - * Authentication URL for the pending OIDC flow, if any. - * @type {?string} + * Retry by starting a new OIDC authentication flow. + * @param {object} e */ - get authURL() { - return this.session.data.pending.oidc.attributes.auth_url; + @action + async retryAuthentication(e) { + // TODO: This event handler can be removed when rose dialog gets + // refactored to use hds. + e.preventDefault(); + + const scope = this.authMethod.scope; + const authenticatorName = `authenticator:${this.authMethod.type}`; + await this.authenticateMethod.startOIDCAuthentication(authenticatorName, { + scope, + authMethod: this.authMethod, + }); } } diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js b/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js index c26837df8..a2a729bc6 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js @@ -33,6 +33,16 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route { return oidc.attemptFetchToken({ scope, authMethod }); } + /** + * Adds the auth-method to the controller context. + * @param {Controller} controller + */ + setupController(controller) { + super.setupController(...arguments); + const authMethod = this.modelFor('scopes.scope.authenticate.method'); + controller.authMethod = authMethod; + } + @runEvery(POLL_TIMEOUT_SECONDS * 1000) poller() { this.refresh(); diff --git a/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs b/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs index 01d1d5256..002c73bfe 100644 --- a/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs +++ b/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs @@ -12,7 +12,7 @@
{{t 'resources.auth-method.messages.pending.description'}}
{{t 'resources.auth-method.questions.no-see-window'}} - + {{t 'actions.retry'}}
diff --git a/ui/desktop/app/controllers/scopes/scope/authenticate/method/oidc.js b/ui/desktop/app/controllers/scopes/scope/authenticate/method/oidc.js index c64b230c3..31bbec879 100644 --- a/ui/desktop/app/controllers/scopes/scope/authenticate/method/oidc.js +++ b/ui/desktop/app/controllers/scopes/scope/authenticate/method/oidc.js @@ -3,21 +3,34 @@ * SPDX-License-Identifier: BUSL-1.1 */ -import Controller from '@ember/controller'; +import Controller, { inject as controller } from '@ember/controller'; +import { action } from '@ember/object'; import { inject as service } from '@ember/service'; export default class ScopesScopeAuthenticateMethodOidcController extends Controller { + @controller('scopes/scope/authenticate/method/index') authenticateMethod; + // =services @service session; - // =attributes + // =actions /** - * Authentication URL for the pending OIDC flow, if any. - * @type {?string} + * Retry by starting a new OIDC authentication flow. + * @param {object} e */ - get authURL() { - return this.session.data.pending.oidc.attributes.auth_url; + @action + async retryAuthentication(e) { + // TODO: This event handler can be removed when rose dialog gets + // refactored to use hds. + e.preventDefault(); + + const scope = this.authMethod.scope; + const authenticatorName = `authenticator:${this.authMethod.type}`; + await this.authenticateMethod.startOIDCAuthentication(authenticatorName, { + scope, + authMethod: this.authMethod, + }); } } diff --git a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js index 0c50090f5..1ca7eccc3 100644 --- a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js +++ b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js @@ -31,6 +31,16 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route { return oidc.attemptFetchToken({ scope, authMethod }); } + /** + * Adds the auth-method to the controller context. + * @param {Controller} controller + */ + setupController(controller) { + super.setupController(...arguments); + const authMethod = this.modelFor('scopes.scope.authenticate.method'); + controller.authMethod = authMethod; + } + @runEvery(POLL_TIMEOUT_SECONDS * 1000) poller() { this.refresh(); diff --git a/ui/desktop/app/templates/scopes/scope/authenticate/method/oidc.hbs b/ui/desktop/app/templates/scopes/scope/authenticate/method/oidc.hbs index 00f529749..04724a850 100644 --- a/ui/desktop/app/templates/scopes/scope/authenticate/method/oidc.hbs +++ b/ui/desktop/app/templates/scopes/scope/authenticate/method/oidc.hbs @@ -11,7 +11,7 @@{{t 'resources.auth-method.messages.pending.description'}}
{{t 'resources.auth-method.questions.no-see-window'}} - + {{t 'actions.retry'}}