Files
threshold-ui/addons/api/addon/models/auth-method.js
T

140 lines
2.7 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
2020-06-17 18:00:38 -04:00
import GeneratedAuthMethodModel from '../generated/models/auth-method';
import { equal } from '@ember/object/computed';
2020-06-17 18:00:38 -04:00
export const TYPE_AUTH_METHOD_PASSWORD = 'password';
export const TYPE_AUTH_METHOD_OIDC = 'oidc';
export const TYPE_AUTH_METHOD_LDAP = 'ldap';
export const TYPES_AUTH_METHOD = Object.freeze([
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
]);
2021-05-14 12:05:09 -04:00
/**
* Enum options per auth method type and field.
2021-05-14 12:05:09 -04:00
*/
export const options = {
state: ['inactive', 'active-private', 'active-public'],
2021-05-14 12:05:09 -04:00
oidc: {
signing_algorithms: [
2021-05-14 12:05:09 -04:00
'RS256',
'RS384',
'RS512',
'ES256',
'ES384',
'ES512',
'PS256',
'PS384',
'PS512',
'EdDSA',
],
account_claim_maps: {
to: ['sub', 'name', 'email'],
},
2023-12-08 09:17:36 -08:00
prompts: ['consent', 'select_account', 'login'],
2021-05-14 12:05:09 -04:00
},
ldap: {
account_attribute_maps: {
to: ['fullName', 'email'],
},
dereference_aliases: {
NeverDerefAliases: 'never',
DerefInSearching: 'searching',
DerefFindingBaseObj: 'finding',
DerefAlways: 'always',
},
},
2021-05-14 12:05:09 -04:00
};
export default class AuthMethodModel extends GeneratedAuthMethodModel {
// =attributes
2021-03-26 12:47:49 -04:00
/**
* @type {boolean}
*/
2021-04-14 11:28:07 -04:00
@equal('is_primary', true) isPrimary;
2021-04-01 15:24:49 -04:00
2022-01-14 16:56:59 -05:00
options = options;
/**
* @type {boolean}
*/
get isPassword() {
return this.type === TYPE_AUTH_METHOD_PASSWORD;
}
/**
* @type {boolean}
*/
get isOIDC() {
return this.type === TYPE_AUTH_METHOD_OIDC;
}
/**
* @type {boolean}
*/
get isLDAP() {
return this.type === TYPE_AUTH_METHOD_LDAP;
}
/**
* @type {boolean}
*/
get isUnknown() {
return !TYPES_AUTH_METHOD.includes(this.type);
}
2021-05-13 14:10:37 -04:00
/**
* @type {boolean}
*/
get isInactive() {
return this.state === 'inactive';
}
/**
* @type {boolean}
*/
get isPrivate() {
return this.state === 'active-private';
}
/**
* @type {boolean}
*/
get isPublic() {
return this.state === 'active-public';
}
2021-05-13 14:10:37 -04:00
// =methods
/**
* Change the active and visibility state of an OIDC and LDAP auth method
2021-05-13 14:10:37 -04:00
* given its ID.
* For OIDC and LDAP auth methods only.
2021-05-13 14:10:37 -04:00
* @param {[string]} state
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
changeState(state, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
state,
};
if (this.isOIDC) {
defaultAdapterOptions.method = 'change-state';
}
2021-05-13 14:10:37 -04:00
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions,
},
});
}
}