-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathKerberosHttpAuthentication.ts
More file actions
50 lines (43 loc) · 1.72 KB
/
KerberosHttpAuthentication.ts
File metadata and controls
50 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import IAuthentication from "../contracts/IAuthentication";
import ITransport from "../contracts/ITransport";
import { AuthOptions } from '../types/AuthOptions';
import { IKerberosAuthProcess } from "../contracts/IKerberosAuthProcess";
import { IKerberosClient } from "../contracts/IKerberosClient";
type HttpAuthOptions = AuthOptions & {
headers?: object
};
export default class KerberosHttpAuthentication implements IAuthentication {
private username: string;
private password: string;
private headers: object;
private authProcess: IKerberosAuthProcess;
constructor(options: HttpAuthOptions, authProcess: IKerberosAuthProcess) {
this.username = options?.username || 'anonymous';
this.password = options?.password !== undefined ? options.password : 'anonymous';
this.headers = options?.headers || {};
this.authProcess = authProcess;
}
authenticate(transport: ITransport): Promise<ITransport> {
return new Promise((resolve, reject) => {
this.authProcess.init({
username: this.username,
password: this.password,
http: true
}, (error: Error, client: IKerberosClient) => {
if (error) {
return reject(error);
}
client.step('', (error: Error, token: string) => {
if (error) {
return reject(error);
}
transport.setOptions('headers', {
...(this.headers),
Authorization: 'Negotiate : ' + token
});
resolve(transport);
});
});
});
}
}