1 |
|
2 |
|
3 | import { HttpHeaders } from "../httpHeaders";
|
4 | import * as base64 from "../util/base64";
|
5 | import { Constants } from "../util/constants";
|
6 | var HeaderConstants = Constants.HeaderConstants;
|
7 | var DEFAULT_AUTHORIZATION_SCHEME = "Basic";
|
8 | var BasicAuthenticationCredentials = (function () {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function BasicAuthenticationCredentials(userName, password, authorizationScheme) {
|
18 | if (authorizationScheme === void 0) { authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME; }
|
19 | this.authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME;
|
20 | if (userName === null || userName === undefined || typeof userName.valueOf() !== "string") {
|
21 | throw new Error("userName cannot be null or undefined and must be of type string.");
|
22 | }
|
23 | if (password === null || password === undefined || typeof password.valueOf() !== "string") {
|
24 | throw new Error("password cannot be null or undefined and must be of type string.");
|
25 | }
|
26 | this.userName = userName;
|
27 | this.password = password;
|
28 | this.authorizationScheme = authorizationScheme;
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | BasicAuthenticationCredentials.prototype.signRequest = function (webResource) {
|
37 | var credentials = this.userName + ":" + this.password;
|
38 | var encodedCredentials = this.authorizationScheme + " " + base64.encodeString(credentials);
|
39 | if (!webResource.headers)
|
40 | webResource.headers = new HttpHeaders();
|
41 | webResource.headers.set(HeaderConstants.AUTHORIZATION, encodedCredentials);
|
42 | return Promise.resolve(webResource);
|
43 | };
|
44 | return BasicAuthenticationCredentials;
|
45 | }());
|
46 | export { BasicAuthenticationCredentials };
|
47 |
|
\ | No newline at end of file |