Files
threshold-ui/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js
T

55 lines
1.7 KiB
JavaScript
Raw Normal View History

import Route from '@ember/routing/route';
2021-01-22 17:01:12 -05:00
import { getOwner } from '@ember/application';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import runEvery from 'ember-pollster/decorators/route/run-every';
import { notifyError } from 'core/decorators/notify';
2021-01-22 17:01:12 -05:00
import config from '../../../../../config/environment';
const POLL_TIMEOUT_SECONDS = config.oidcPollingTimeoutSeconds;
export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
2021-01-22 17:01:12 -05:00
// =services
@service session;
@service windowManager;
@service router;
2021-01-22 17:01:12 -05:00
// =methods
beforeModel;
2021-01-22 17:01:12 -05:00
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
2021-03-15 16:18:22 -04:00
return oidc.attemptFetchToken({ scope, authMethod });
2021-01-22 17:01:12 -05:00
}
@runEvery(POLL_TIMEOUT_SECONDS * 1000)
poller() {
this.refresh();
2021-01-22 17:01:12 -05:00
}
/**
* When this route is deactivated (exited), stop polling for changes and close
* any windows opened via the window manager service.
2021-01-22 17:01:12 -05:00
*/
deactivate() {
this.windowManager.closeAll();
2021-01-22 17:01:12 -05:00
}
/**
* An error in this route indicates authentication failed. The user is
* notified and returned to the index.
*/
@action
@notifyError(() => 'errors.authentication-failed.title', { catch: true })
error(e) {
this.router.transitionTo('scopes.scope.authenticate.method.index');
// rethrow the error to activate the notifyError decorator
throw e;
}
}