2020-07-24 17:05:55 -04:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import { action } from '@ember/object';
|
2020-09-25 18:09:56 -04:00
|
|
|
import loading from 'ember-loading/decorator';
|
2021-01-06 12:53:57 -05:00
|
|
|
import { notifyError } from 'core/decorators/notify';
|
2020-07-24 17:05:55 -04:00
|
|
|
|
|
|
|
|
export default class ScopesScopeAuthenticateMethodRoute extends Route {
|
|
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service session;
|
|
|
|
|
@service notify;
|
|
|
|
|
@service intl;
|
|
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an auth method by id.
|
|
|
|
|
* @param {object} params
|
|
|
|
|
* @return {Promise{AuthMethodModel}}
|
|
|
|
|
*/
|
|
|
|
|
model({ auth_method_id: id }) {
|
|
|
|
|
const adapterOptions = { scopeID: this.modelFor('scopes.scope').id };
|
|
|
|
|
return this.store.findRecord('auth-method', id, adapterOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =actions
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-06 12:53:57 -05:00
|
|
|
* Delegates authentication to an authenticator of type matching the current
|
|
|
|
|
* auth method. If authentication fails, notifies with an alert.
|
2020-07-24 17:05:55 -04:00
|
|
|
*/
|
|
|
|
|
@action
|
2020-09-25 18:09:56 -04:00
|
|
|
@loading
|
2021-01-06 12:53:57 -05:00
|
|
|
@notifyError(() => 'errors.authentication-failed.title', { catch: true })
|
2020-07-24 17:05:55 -04:00
|
|
|
async authenticate(creds) {
|
|
|
|
|
const scope = this.modelFor('scopes.scope');
|
2021-01-06 12:53:57 -05:00
|
|
|
const authMethod = this.modelFor('scopes.scope.authenticate.method');
|
|
|
|
|
const authenticatorName = `authenticator:${authMethod.type}`;
|
2020-07-24 17:05:55 -04:00
|
|
|
const requestCookies = false;
|
2021-03-05 17:27:00 -05:00
|
|
|
await this.session.authenticate(authenticatorName, creds, requestCookies, {
|
|
|
|
|
scope,
|
|
|
|
|
authMethod,
|
|
|
|
|
});
|
2021-01-06 12:53:57 -05:00
|
|
|
this.transitionTo('index');
|
2020-07-24 17:05:55 -04:00
|
|
|
}
|
|
|
|
|
}
|