Credentials configuration module
This module helps to quickly create lwc page with custom set of required credential fields (e.g. for API integration). It consists of three parts:
- Credentials Form (LWC)
- APEX classes (Controller)
- Custom Settings (Data model and storage)
Credentials form
It represents a form with the current user credentials and with the ability to edit and save data.
No configuration needed here. Simply, put c-credentials-config component where it needs to be.
APEX classes
In order to validate user credentials before saving, you have to extend CredentialsValidator class and override one method
AqResult validate(Map<String, String> credentials)
You can use an existing AqTest_CredentialsValidator.ExampleCredentialsValidator as an example. Put the name of the created class to CredentialCustomValidator__c settings (see Custom Validator Class below).
Custom Settings
For proper functioning of the module, you will have to add new Custom Settings values. There are three Custom Settings objects:
Custom Validator Class
or CredentialCustomValidator__c settings. Use it to store the name of the class that extends CredentialsValidator (e.g. 'ExampleCredentialsValidator').
Add a settings record populating class name to 'Validator Class Name' (ClassName__c) field.
Integration Credential Fields
or CredentialsFields__c represents a set of required fields to be filled by user (on the Form). It is the List CustomSettings.
Start with filling the required fields:
- Field Name: Case insensitive field name to store user value
- Field label: Title of the corresponding input component to be displayed on the Form
There are more non-required fields for deeper configuration:
- Field position order: Unique number used to sort fields on the page
- Input field size: Consider it as a Picklist.
small,mediumandlargeto fill 1/3, 1/2 and 1/1 width of the Form - Input type: Consider it as a Picklist.
passwordto display password input,textareato input values larger than 255 symbols (e.g. tokens),text- otherwise (default value)
Integration Credentials
or Credentials__c are hierarchical Custom Settings to store user credentials.
It is required that every CredentialsFields__c value (i.e. every credential field) has the matching field in Credentials__c Custom Settings (use CredentialsFields__c.Name__c as Field Name for Credentials__c).
For convenience, Credentials__c already has some frequently used fields (e.g. 'Password', so you don't need to add it here after putting it as a CredentialsFields__c value).
Token fields
To store large values (255 - 1020 symbols) after marking it as a textarea in CredentialsFields__c you have to add 4 fields to Credentials__c adding 1, 2, 3 and 4 to the end of the FieldName.
For example, we want an Access Token to be inserted by a user. Firstly, create new CredentialsFields__c record: Label: 'Access Token', Name: 'AccessToken', Type: 'textarea'. And then add 4 corresponding Credentials__c fields: with Name AccessToken1, AccessToken2, AccessToken3, AccessToken4 (put 255 as a Length, the Label is arbitrary).