UNPKG

5.71 kBTypeScriptView Raw
1/** @module auth */
2import { ConfigParams } from 'pip-services3-commons-node';
3/**
4 * Contains credentials to authenticate against external services.
5 * They are used together with connection parameters, but usually stored
6 * in a separate store, protected from unauthorized access.
7 *
8 * ### Configuration parameters ###
9 *
10 * - store_key: key to retrieve parameters from credential store
11 * - username: user name
12 * - user: alternative to username
13 * - password: user password
14 * - pass: alternative to password
15 * - access_id: application access id
16 * - client_id: alternative to access_id
17 * - access_key: application secret key
18 * - client_key: alternative to access_key
19 * - secret_key: alternative to access_key
20 *
21 * In addition to standard parameters CredentialParams may contain any number of custom parameters
22 *
23 * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/classes/config.configparams.html ConfigParams]]
24 * @see [[ConnectionParams]]
25 * @see [[CredentialResolver]]
26 * @see [[ICredentialStore]]
27 *
28 * ### Example ###
29 *
30 * let credential = CredentialParams.fromTuples(
31 * "user", "jdoe",
32 * "pass", "pass123",
33 * "pin", "321"
34 * );
35 *
36 * let username = credential.getUsername(); // Result: "jdoe"
37 * let password = credential.getPassword(); // Result: "pass123"
38 * let pin = credential.getAsNullableString("pin"); // Result: 321
39 */
40export declare class CredentialParams extends ConfigParams {
41 /**
42 * Creates a new credential parameters and fills it with values.
43 *
44 * @param values (optional) an object to be converted into key-value pairs to initialize these credentials.
45 */
46 constructor(values?: any);
47 /**
48 * Checks if these credential parameters shall be retrieved from [[CredentialStore]].
49 * The credential parameters are redirected to [[CredentialStore]] when store_key parameter is set.
50 *
51 * @returns true if credentials shall be retrieved from [[CredentialStore]]
52 *
53 * @see [[getStoreKey]]
54 */
55 useCredentialStore(): boolean;
56 /**
57 * Gets the key to retrieve these credentials from [[CredentialStore]].
58 * If this key is null, than all parameters are already present.
59 *
60 * @returns the store key to retrieve credentials.
61 *
62 * @see [[useCredentialStore]]
63 */
64 getStoreKey(): string;
65 /**
66 * Sets the key to retrieve these parameters from [[CredentialStore]].
67 *
68 * @param value a new key to retrieve credentials.
69 */
70 setStoreKey(value: string): void;
71 /**
72 * Gets the user name.
73 * The value can be stored in parameters "username" or "user".
74 *
75 * @returns the user name.
76 */
77 getUsername(): string;
78 /**
79 * Sets the user name.
80 *
81 * @param value a new user name.
82 */
83 setUsername(value: string): void;
84 /**
85 * Get the user password.
86 * The value can be stored in parameters "password" or "pass".
87 *
88 * @returns the user password.
89 */
90 getPassword(): string;
91 /**
92 * Sets the user password.
93 *
94 * @param value a new user password.
95 */
96 setPassword(value: string): void;
97 /**
98 * Gets the application access id.
99 * The value can be stored in parameters "access_id" pr "client_id"
100 *
101 * @returns the application access id.
102 */
103 getAccessId(): string;
104 /**
105 * Sets the application access id.
106 *
107 * @param value a new application access id.
108 */
109 setAccessId(value: string): void;
110 /**
111 * Gets the application secret key.
112 * The value can be stored in parameters "access_key", "client_key" or "secret_key".
113 *
114 * @returns the application secret key.
115 */
116 getAccessKey(): string;
117 /**
118 * Sets the application secret key.
119 *
120 * @param value a new application secret key.
121 */
122 setAccessKey(value: string): void;
123 /**
124 * Creates a new CredentialParams object filled with key-value pairs serialized as a string.
125 *
126 * @param line a string with serialized key-value pairs as "key1=value1;key2=value2;..."
127 * Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
128 * @returns a new CredentialParams object.
129 */
130 static fromString(line: string): CredentialParams;
131 /**
132 * Creates a new CredentialParams object filled with provided key-value pairs called tuples.
133 * Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.
134 *
135 * @param tuples the tuples to fill a new CredentialParams object.
136 * @returns a new CredentialParams object.
137 */
138 static fromTuples(...tuples: any[]): CredentialParams;
139 /**
140 * Retrieves all CredentialParams from configuration parameters
141 * from "credentials" section. If "credential" section is present instead,
142 * than it returns a list with only one CredentialParams.
143 *
144 * @param config a configuration parameters to retrieve credentials
145 * @returns a list of retrieved CredentialParams
146 */
147 static manyFromConfig(config: ConfigParams): CredentialParams[];
148 /**
149 * Retrieves a single CredentialParams from configuration parameters
150 * from "credential" section. If "credentials" section is present instead,
151 * then is returns only the first credential element.
152 *
153 * @param config ConfigParams, containing a section named "credential(s)".
154 * @returns the generated CredentialParams object.
155 *
156 * @see [[manyFromConfig]]
157 */
158 static fromConfig(config: ConfigParams): CredentialParams;
159}