refactor: 💡 remove route action usage for scopes (#2385)
* refactor: 💡 remove route action usage for scopes ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13755
This commit is contained in:
1 parent
9e668e8467
commit
0af81d9bc1
27 files changed
+755
-260
No files matched your search
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { notifyError } from 'core/decorators/notify';
|
||||
import {
|
||||
TYPE_AUTH_METHOD_PASSWORD,
|
||||
TYPE_AUTH_METHOD_OIDC,
|
||||
TYPE_AUTH_METHOD_LDAP,
|
||||
} from 'api/models/auth-method';
|
||||
|
||||
export default class ScopesScopeAuthenticateMethodIndexController extends Controller {
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
@service windowManager;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Delegates authentication to an authenticator of type matching the current
|
||||
* auth method. If authentication fails, notifies with an alert.
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(() => 'errors.authentication-failed.title', {
|
||||
sticky: false,
|
||||
catch: true,
|
||||
})
|
||||
async authenticate(authMethod, creds) {
|
||||
const scope = authMethod.scope;
|
||||
const authenticatorName = `authenticator:${authMethod.type}`;
|
||||
const requestCookies = false;
|
||||
switch (authMethod.type) {
|
||||
case TYPE_AUTH_METHOD_PASSWORD:
|
||||
case TYPE_AUTH_METHOD_LDAP:
|
||||
await this.session.authenticate(
|
||||
authenticatorName,
|
||||
creds,
|
||||
requestCookies,
|
||||
{ scope, authMethod },
|
||||
);
|
||||
this.router.transitionTo('index');
|
||||
break;
|
||||
case TYPE_AUTH_METHOD_OIDC:
|
||||
await this.startOIDCAuthentication(authenticatorName, {
|
||||
scope,
|
||||
authMethod,
|
||||
});
|
||||
this.router.transitionTo('scopes.scope.authenticate.method.oidc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks off the OIDC auth flow by opening a new window to the provider.
|
||||
* @param {string} authenticatorName
|
||||
* @param {object} options
|
||||
*/
|
||||
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.windowManager.open(json.attributes.auth_url);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeAuthenticateMethodOidcController extends Controller {
|
||||
@controller('scopes/scope/authenticate/method/index') authMethod;
|
||||
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
|
||||
Reference in new issue
Block a user