feature: initial OIDC authentication flow
This commit is contained in:
7 files changed
+201
-31
No files matched your search
@@ -51,7 +51,6 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route {
|
||||
case 'oidc':
|
||||
await this.startOIDCAuthentication(
|
||||
authenticatorName,
|
||||
creds,
|
||||
requestCookies,
|
||||
{ scope, authMethod }
|
||||
);
|
||||
@@ -60,8 +59,25 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route {
|
||||
}
|
||||
}
|
||||
|
||||
async startOIDCAuthentication(authenticatorName, creds, requestCookies, options) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async startOIDCAuthentication(authenticatorName, requestCookies, options) {
|
||||
const oidc = getOwner(this).lookup(authenticatorName);
|
||||
oidc.startAuthentication(creds, requestCookies, options);
|
||||
// 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(requestCookies, options);
|
||||
await this.openExternalOIDCFlow(json.authorization_request_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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,67 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { task, timeout } from 'ember-concurrency';
|
||||
import config from '../../../../../config/environment';
|
||||
|
||||
const POLL_TIMEOUT_SECONDS = config.oidcPollingTimeoutSeconds;
|
||||
|
||||
export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* A simple Ember Concurrency-based polling task that refreshes the route
|
||||
* every POLL_TIMEOUT_SECONDS seconds. This is necessary to display changes
|
||||
* to session `status` that may occur.
|
||||
*
|
||||
* NOTE: tasks are sort of attributes and sort of methods, but they are not
|
||||
* language-level constructs. Thus we annotate this task as if it
|
||||
* is an attribute.
|
||||
* @type {Task}
|
||||
*/
|
||||
@task(function * () {
|
||||
while(!this.session.isAuthenticated) {
|
||||
yield timeout(POLL_TIMEOUT_SECONDS * 1000);
|
||||
yield this.refresh();
|
||||
}
|
||||
}).drop() poller;
|
||||
|
||||
// =methods
|
||||
|
||||
model() {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const authMethod = this.modelFor('scopes.scope.authenticate.method');
|
||||
const authenticatorName = `authenticator:${authMethod.type}`;
|
||||
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
|
||||
return oidc.attemptOIDCAuthentication({ scope, authMethod });
|
||||
}
|
||||
|
||||
/**
|
||||
* If authenticated, redirects to index for further processing.
|
||||
*/
|
||||
redirect() {
|
||||
if (this.session.isAuthenticated) this.replaceWith('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* When this route is activated (entered), begin polling for changes.
|
||||
*/
|
||||
activate() {
|
||||
this.poller.perform();
|
||||
}
|
||||
|
||||
/**
|
||||
* When this route is deactivated (exited), stop polling for changes.
|
||||
*/
|
||||
deactivate() {
|
||||
this.poller.cancelAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
OIDC yay!
|
||||
Checking for OIDC ready …
|
||||
@@ -36,6 +36,7 @@ module.exports = function (environment) {
|
||||
|
||||
notifyTimeout: 4000,
|
||||
sessionPollingTimeoutSeconds: 2.5,
|
||||
oidcPollingTimeoutSeconds: 1,
|
||||
|
||||
documentation: {
|
||||
baseURL: 'https://boundaryproject.io/help/admin-ui',
|
||||
|
||||
Reference in new issue
Block a user