From 92640b96aaa50754e7cc729536229e561e274bcf Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 15 Jan 2021 11:10:33 -0500 Subject: [PATCH] wip: OIDC authenticator --- addons/api/mirage/factories/auth-method.js | 8 ++++++ addons/api/mirage/scenarios/default.js | 2 +- addons/auth/addon/authenticators/oidc.js | 26 +++++++++++++++++++ .../tests/unit/authenticators/oidc-test.js | 8 ++++++ addons/core/addon/authenticators/oidc.js | 8 ++++++ .../form/authenticate/oidc/index.hbs | 13 ++++++++++ addons/core/app/authenticators/oidc.js | 1 + .../app/components/form/authenticate/oidc.js | 1 + .../components/form/authenticate/oidc-test.js | 26 +++++++++++++++++++ 9 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 addons/auth/addon/authenticators/oidc.js create mode 100644 addons/auth/tests/unit/authenticators/oidc-test.js create mode 100644 addons/core/addon/authenticators/oidc.js create mode 100644 addons/core/addon/components/form/authenticate/oidc/index.hbs create mode 100644 addons/core/app/authenticators/oidc.js create mode 100644 addons/core/app/components/form/authenticate/oidc.js create mode 100644 addons/core/tests/integration/components/form/authenticate/oidc-test.js diff --git a/addons/api/mirage/factories/auth-method.js b/addons/api/mirage/factories/auth-method.js index 61d29726b..ec2c62064 100644 --- a/addons/api/mirage/factories/auth-method.js +++ b/addons/api/mirage/factories/auth-method.js @@ -1,9 +1,17 @@ import factory from '../generated/factories/auth-method'; import { trait } from 'ember-cli-mirage'; +const types = [ + 'password', + 'oidc' +]; + export default factory.extend({ id: (i) => `auth-method-id-${i}`, + // Cycle through available types + type: (i) => types[i % types.length], + /** * Adds accounts (with associated users) to auth method. */ diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js index cc821e6dd..9bed5a325 100644 --- a/addons/api/mirage/scenarios/default.js +++ b/addons/api/mirage/scenarios/default.js @@ -14,7 +14,7 @@ export default function(server) { }, 'withChildren')[0]; // Auth - server.createList('auth-method', 1, { scope: globalScope }, 'withAccountsAndUsers'); + server.createList('auth-method', 2, { scope: globalScope }, 'withAccountsAndUsers'); server.createList('auth-method', 3, { scope: orgScope }, 'withAccountsAndUsers'); // Groups and Users diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js new file mode 100644 index 000000000..0d641da41 --- /dev/null +++ b/addons/auth/addon/authenticators/oidc.js @@ -0,0 +1,26 @@ +import BaseAuthenticator from './base'; +// import { resolve, reject } from 'rsvp'; +// import fetch from 'fetch'; +import { Promise } from 'rsvp'; + +/** + * + */ +export default class OIDCAuthenticator extends BaseAuthenticator { + + // =unimplemented methods + // TODO: implement ;-) + + buildAuthEndpointURL(/* { + scope: { id: scopeID }, + authMethod: { id: authMethodID }, + } */) { } + + async authenticate( + creds, + requestCookies = true, + options + ) { + return false; + } +} diff --git a/addons/auth/tests/unit/authenticators/oidc-test.js b/addons/auth/tests/unit/authenticators/oidc-test.js new file mode 100644 index 000000000..0d4a9b492 --- /dev/null +++ b/addons/auth/tests/unit/authenticators/oidc-test.js @@ -0,0 +1,8 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; + +module('Unit | Authenticator | OIDC', function (hooks) { + setupTest(hooks); + setupMirage(hooks); +}); diff --git a/addons/core/addon/authenticators/oidc.js b/addons/core/addon/authenticators/oidc.js new file mode 100644 index 000000000..77dd7e29e --- /dev/null +++ b/addons/core/addon/authenticators/oidc.js @@ -0,0 +1,8 @@ +import BaseOIDCAuthenticator from 'auth/authenticators/oidc'; +//import { inject as service } from '@ember/service'; + +/** + * + */ +export default class OIDCAuthenticator extends BaseOIDCAuthenticator { +} diff --git a/addons/core/addon/components/form/authenticate/oidc/index.hbs b/addons/core/addon/components/form/authenticate/oidc/index.hbs new file mode 100644 index 000000000..e8e1294fe --- /dev/null +++ b/addons/core/addon/components/form/authenticate/oidc/index.hbs @@ -0,0 +1,13 @@ + + + + + diff --git a/addons/core/app/authenticators/oidc.js b/addons/core/app/authenticators/oidc.js new file mode 100644 index 000000000..2299b299d --- /dev/null +++ b/addons/core/app/authenticators/oidc.js @@ -0,0 +1 @@ +export { default } from 'core/authenticators/oidc'; diff --git a/addons/core/app/components/form/authenticate/oidc.js b/addons/core/app/components/form/authenticate/oidc.js new file mode 100644 index 000000000..cbb3b8ab4 --- /dev/null +++ b/addons/core/app/components/form/authenticate/oidc.js @@ -0,0 +1 @@ +export { default } from 'core/components/form/authenticate/oidc'; \ No newline at end of file diff --git a/addons/core/tests/integration/components/form/authenticate/oidc-test.js b/addons/core/tests/integration/components/form/authenticate/oidc-test.js new file mode 100644 index 000000000..3345d3e3d --- /dev/null +++ b/addons/core/tests/integration/components/form/authenticate/oidc-test.js @@ -0,0 +1,26 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | form/authenticate/oidc', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + + await render(hbs``); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +});