Implemets: ConfigParams
Description
The CredentialParams class allows you to create credential parameters that can be used to authenticate against external services.
Important points
- Credential parameters are used together with connection parameters, but usually stored in a separate store, protected from unauthorized access.
Configuration parameters
- store_key: key to retrieve parameters from credential store
- username: user name
- user: alternative to username
- password: user’s password
- pass: alternative to password
- access_id: application access id
- client_id: alternative to access_id
- access_key: application secret key
- client_key: alternative to access_key
- secret_key: alternative to access_key
In addition to standard parameters CredentialParams may contain any number of custom parameters.
Constructors
Creates a new credential parameters and fills it with values.
publicCredentialParams(IDictionary<string, string> values)
- values: IDictionary<string, string> - (optional) object to be converted into key-value pairs to initialize these credentials.
Creates an empty instance of credential parameters.
publicCredentialParams()
Properties
UseCredentialStore
Checks if these credential parameters shall be retrieved from ICredentialStore. The credential parameters are redirected to ICredentialStore when store_key parameter is set.
publicbool UseCredentialStore { get; }
StoreKey
Gets and sets the key to retrieve these credentials from ICredentialStore. If this key is null, then all parameters are already present.
publicstring StoreKey { get; set; }
Username
Gets and sets the username. The value can be stored in the parameters “username” or “user”.
publicstring Username { get; set; }
Password
Gets and sets the user’s password. The value can be stored in parameters “password” or “pass”.
publicstring Password { get; set; }
AccessId
Gets and sets the application access id. The value can be stored in parameters “access_id” pr “client_id”
publicstring AccessId { get; set; }
AccessKey
Gets and sets the application secret key. The value can be stored in parameters “access_key”, “client_key” or “secret_key”.
publicstring AccessKey { get; set; }
Static methods
FromConfig
Retrieves a single CredentialParams from configuration parameters from “credential” section. If “credentials” section is present instead, then it returns only the first credential element.
public staticCredentialParams FromConfig(ConfigParams config)
- config: ConfigParams - containing a section named “credential(s)”.
- returns: CredentialParams - generated CredentialParams object.
FromString
Creates a new CredentialParams object filled with key-value pairs serialized as a string.
public new staticCredentialParams FromString(string line)
- line: string - string with serialized key-value pairs as “key1=value1;key2=value2;…" Example: “Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z”
- returns: CredentialParams - new CredentialParams object.
ManyFromConfig
Retrieves all CredentialParams from configuration parameters from the “credentials” section. If the “credential” section is present instead, then it returns a list with only one CredentialParams.
public staticList<CredentialParams> ManyFromConfig(ConfigParams config)
- config: ConfigParams - configuration parameters to retrieve credentials
- returns: List<CredentialParams> - list of retrieved CredentialParams
Examples
var credential = CredentialParams.FromTuples(
"user", "jdoe",
"pass", "pass123",
"pin", "321"
);
var username = credential.GetUsername(); // Result: "jdoe"
var password = credential.GetPassword(); // Result: "pass123"
var pin = credential.GetAsNullableString("pin"); // Result: 321