Files
threshold-ui/ui/admin/app/components/form/auth-method/oidc/index.js
T
Lisbet Alvarez 3ba93927fe Update copyright headers (#3146)
* empty commit

* Add missing copyright headers

* chore: 🤖 update copywrite config file with correct year

* Add missing copyright headers

* empty commit (gh action merge checks are stuck)
2026-01-28 17:09:06 -08:00

92 lines
2.1 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { options } from 'api/models/auth-method';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class FormAuthMethodOidcComponent extends Component {
// =attributes
/**
* @type {object}
*/
signingAlgorithms = options.oidc.signing_algorithms;
/**
* @type {object}
*/
toClaims = options.oidc.account_claim_maps.to;
/**
* @type {string}
*/
newToClaim = options.oidc.account_claim_maps.to[0];
/**
* @type {string}
*/
newSigningAlgorithm = options.oidc.signing_algorithms[0];
/**
* @type {string}
*/
prompts = options.oidc.prompts;
@tracked selectedPrompts = this.parsePromptsArray();
@tracked skipPromptsList = this.isToggleChecked();
/**
* @returns {string}
*/
parsePromptsArray() {
return this.args.model.prompts?.map((item) => item.value) ?? [];
}
/**
* @returns {boolean}
*/
isToggleChecked() {
return this.args.model.prompts?.find((i) => i.value === 'none');
}
//actions
/**
* @param {string} value
*/
@action
toggleField(value) {
this.skipPromptsList = !this.skipPromptsList;
//If toggle is on, then add `none` to model, else remove it
if (this.skipPromptsList) {
this.args.model.prompts = [{ value }];
} else {
this.args.model.prompts = [];
}
}
/**
* @param {string} option
* @param {object} event
*/
@action
updatePrompt(value, event) {
const currentSelection = { value };
const previousSelection = this.args.model.prompts || [];
// Add the selected option to the model, only when the checkbox is in checked state
if (event.target.checked) {
this.args.model.prompts = [...previousSelection, currentSelection];
} else {
// When the checkbox is unchecked, remove the option form the exisiting list
const removeSelection = previousSelection.filter(
(prompt) => prompt.value !== value,
);
this.args.model.prompts = [...removeSelection];
}
}
}