From 5f342a0ee874ea8bd14a2f4adf2d5c1abc10d250 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 12 Apr 2021 17:10:55 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20"retry"=20is=20a=20l?= =?UTF-8?q?ink=20instead=20of=20an=20action=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scopes/scope/authenticate/method/oidc.js | 18 ++++++++ .../scopes/scope/authenticate/method.js | 42 +++++++++---------- .../scopes/scope/authenticate/method/oidc.hbs | 6 ++- .../scope/authenticate/method/oidc-test.js | 17 ++++++++ 4 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js create mode 100644 ui/admin/tests/unit/controllers/scopes/scope/authenticate/method/oidc-test.js diff --git a/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js b/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js new file mode 100644 index 000000000..119f54ed0 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/authenticate/method/oidc.js @@ -0,0 +1,18 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeAuthenticateMethodOidcController extends Controller { + // =services + + @service session; + + // =attributes + + /** + * Authetnication URL for the pending OIDC flow, if any. + * @type {?string} + */ + get authURL() { + return this.session.data.pending.oidc.attributes.auth_url; + } +} diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method.js b/ui/admin/app/routes/scopes/scope/authenticate/method.js index 930c09d35..33dec88f9 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method.js @@ -24,6 +24,27 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { return this.store.findRecord('auth-method', id, adapterOptions); } + /** + * + */ + async startOIDCAuthentication(authenticatorName, options) { + const oidc = getOwner(this).lookup(authenticatorName); + // TODO: delegate this call from the session service so that we don't have + // to look up the authenticator directly + const json = await oidc.startAuthentication(options); + await this.openExternalOIDCFlow(json.attributes.auth_url); + } + + /** + * Opens the specified URL in a new tab or window. By default this uses + * `window.open`, but may be overriden. + * @param {string} url + */ + async openExternalOIDCFlow(url) { + // TODO don't use window directly + await window.open(url); + } + // =actions /** @@ -57,25 +78,4 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { break; } } - - /** - * - */ - async startOIDCAuthentication(authenticatorName, options) { - const oidc = getOwner(this).lookup(authenticatorName); - // TODO: delegate this call from the session service so that we don't have - // to look up the authenticator directly - const json = await oidc.startAuthentication(options); - await this.openExternalOIDCFlow(json.attributes.auth_url); - } - - /** - * Opens the specified URL in a new tab or window. By default this uses - * `window.open`, but may be overriden. - * @param {string} url - */ - async openExternalOIDCFlow(url) { - // TODO don't use window directly - await window.open(url); - } } 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 10422cc66..dedca3ab3 100644 --- a/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs +++ b/ui/admin/app/templates/scopes/scope/authenticate/method/oidc.hbs @@ -7,7 +7,11 @@

{{t 'resources.auth-method.messages.pending.description'}}

{{t 'resources.auth-method.questions.no-see-window'}} - + {{t 'actions.retry'}}

diff --git a/ui/admin/tests/unit/controllers/scopes/scope/authenticate/method/oidc-test.js b/ui/admin/tests/unit/controllers/scopes/scope/authenticate/method/oidc-test.js new file mode 100644 index 000000000..0a98d8794 --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/authenticate/method/oidc-test.js @@ -0,0 +1,17 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module( + 'Unit | Controller | scopes/scope/authenticate/method/oidc', + function (hooks) { + setupTest(hooks); + + // TODO: Replace this with your real tests. + test('it exists', function (assert) { + let controller = this.owner.lookup( + 'controller:scopes/scope/authenticate/method/oidc' + ); + assert.ok(controller); + }); + } +);