CredentialResolver

Helper class used to retrieve component credentials.

Implements: IConfigurable, IReferenceable

Description

The CredentialResolver class is used to retrieve component credentials.

Important points

  • If credentials are configured to be retrieved from ICredentialStore, it will automatically locate ICredentialStore in component references and retrieve the credentials from there using the store_key parameter.

Configuration parameters

credential:

  • store_key: (optional) a key to retrieve the credentials from ICredentialStore
  • : other credential parameters

credentials: alternative to credential

  • [credential params 1]: first credential parameters
    • : credential parameters for key 1
  • [credential params N]: Nth credential parameters
    • : credential parameters for key N

References

  • *:credential-store:*:*:1.0 - (optional) Credential stores to resolve credentials

Constructors

Creates a new instance of credentials resolver.

CredentialResolver([ConfigParams? config, IReferences references])

  • config: ConfigParams - (optional) component configuration parameters
  • references: IReferences - (optional) component references

Instance methods

add

Adds a new credential to component credentials

void add(CredentialParams credential)

configure

Configures component by passing configuration parameters.

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

getAll

Gets all credentials configured in component configuration.

Redirect to CredentialStores is not done at this point. If you need fully fleshed credential use lookup method instead.

List<CredentialParams> getAll()

lookup

Looks up component credential parameters. If credentials are configured to be retrieved from Credential store it finds a ICredentialStore` and lookups credentials there.

Future<CredentialParams?> lookup(String? correlationId)

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • returns: Future<CredentialParams?> - resolved credential parameters or null if nothing was found.

setReferences

Sets references to dependent components.

void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

Examples

var config = ConfigParams.fromTuples([
    'credential.user', 'jdoe',
    'credential.pass',  'pass123'
]);

var credentialResolver = new CredentialResolver();
credentialResolver.configure(config);
credentialResolver.setReferences(references);
credentialResolver.lookup('123', (err, credential) => {
    // Now use credential...
});

See also