2020-06-17 18:00:38 -04:00
|
|
|
import GeneratedAuthMethodModel from '../generated/models/auth-method';
|
2021-06-02 14:23:54 -04:00
|
|
|
import { attr } from '@ember-data/model';
|
2021-05-12 17:12:59 -04:00
|
|
|
import { fragment } from 'ember-data-model-fragments/attributes';
|
2021-03-24 18:36:34 -04:00
|
|
|
import { equal } from '@ember/object/computed';
|
2020-06-17 18:00:38 -04:00
|
|
|
|
2021-05-14 12:05:09 -04:00
|
|
|
/**
|
2021-06-01 22:29:19 -04:00
|
|
|
* Enum options per auth method type and field.
|
2021-05-14 12:05:09 -04:00
|
|
|
*/
|
|
|
|
|
export const options = {
|
|
|
|
|
oidc: {
|
2021-05-20 18:00:48 -04:00
|
|
|
signing_algorithms: [
|
2021-05-14 12:05:09 -04:00
|
|
|
'RS256',
|
|
|
|
|
'RS384',
|
|
|
|
|
'RS512',
|
|
|
|
|
'ES256',
|
|
|
|
|
'ES384',
|
|
|
|
|
'ES512',
|
|
|
|
|
'PS256',
|
|
|
|
|
'PS384',
|
|
|
|
|
'PS512',
|
|
|
|
|
'EdDSA',
|
|
|
|
|
],
|
|
|
|
|
state: ['inactive', 'active-private', 'active-public'],
|
|
|
|
|
account_claim_maps: {
|
|
|
|
|
to: ['sub', 'name', 'email'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-05-12 17:12:59 -04:00
|
|
|
|
2021-03-16 15:41:13 -04:00
|
|
|
export default class AuthMethodModel extends GeneratedAuthMethodModel {
|
2021-06-02 14:23:54 -04:00
|
|
|
// =error attributes
|
|
|
|
|
// These attributes exist solely to capture errors on nested fields.
|
|
|
|
|
// See the application adapter's error normalization method for
|
|
|
|
|
// more information.
|
|
|
|
|
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_state;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_issuer;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_client_id;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_client_secret;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_max_age;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_api_url_prefix;
|
|
|
|
|
@attr('string', { readOnly: true })
|
|
|
|
|
attributes_disable_discovered_config_validation;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_dry_run;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_account_claim_maps;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_claims_scopes;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_signing_algorithms;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_allowed_audiences;
|
|
|
|
|
@attr('string', { readOnly: true }) attributes_idp_ca_certs;
|
|
|
|
|
|
2021-03-16 15:41:13 -04:00
|
|
|
// =attributes
|
|
|
|
|
|
2021-05-12 17:12:59 -04:00
|
|
|
/**
|
|
|
|
|
* Attributes of this resource, if any, represented as a JSON fragment.
|
|
|
|
|
* @type {FragmentAuthMethodAttributesModel}
|
|
|
|
|
*/
|
|
|
|
|
@fragment('fragment-auth-method-attributes', { defaultValue: {} }) 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
|
|
|
|
2021-03-16 15:41:13 -04:00
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isPassword() {
|
|
|
|
|
return this.type === 'password';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isOIDC() {
|
|
|
|
|
return this.type === 'oidc';
|
|
|
|
|
}
|
2021-05-13 14:10:37 -04:00
|
|
|
|
2021-06-03 17:08:40 -04:00
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isInactive() {
|
|
|
|
|
return this.attributes.state === 'inactive';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isPrivate() {
|
|
|
|
|
return this.attributes.state === 'active-private';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isPublic() {
|
|
|
|
|
return this.attributes.state === 'active-public';
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 14:10:37 -04:00
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Change the active and visibility state of an OIDC auth method
|
|
|
|
|
* given its ID.
|
|
|
|
|
* For OIDC auth methods only.
|
|
|
|
|
* @param {[string]} state
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
changeState(state, options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'change-state',
|
|
|
|
|
state,
|
|
|
|
|
};
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-16 15:41:13 -04:00
|
|
|
}
|