This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth-manager.ts
93 lines (82 loc) · 2.7 KB
/
auth-manager.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* istanbul ignore file */
const solidAuthClient = require('solid-auth-client');
const solidAuthClientCLI = require('solid-auth-cli');
/* tslint:disable */
/**
* AuthenticationManager class responsible for authentication of users by WebID
*/
class AuthenticationManager {
static getInstance() {
if (!AuthenticationManager.instance) {
AuthenticationManager.instance = new AuthenticationManager();
}
return AuthenticationManager.instance;
}
private static instance: AuthenticationManager;
private constructor() {
// do something construct...
}
/**
* Forwards fetch requests to solidAuthClient
* @param input RequestInfo object forwared to solidAuthClient library
* @param options Additional options passed into fetch HTTP request
*/
fetch(input: RequestInfo, options: {} = {}): Promise<Response> {
return solidAuthClient.fetch(input, options);
}
/**
* Forwards login requests to solidAuthCLient
* @param idp The string representing solid provider
* @param options Additional properties passed into login
*/
login(idp: string, options: {}): Promise<any> {
return solidAuthClient.login(idp, options);
}
/**
* Notifies the listener about login and logout states of the session
* @param callback Callback to invoke every time session status is updated
*/
async trackSession(callback: Function): Promise<void> {
/* eslint-disable standard/no-callback-literal */
return solidAuthClient.trackSession(callback);
}
/**
* Returns current sessions
* @param storage Reference to browser storage holding the session
*/
async currentSession(storage: any): Promise<any> {
return solidAuthClient.currentSession(storage);
}
}
/**
* Test class used only for unit testing, main difference is the ability to
* authenticate programmatically.
*/
class TestAuthenticationManager {
static getInstance() {
if (!TestAuthenticationManager.instance) {
TestAuthenticationManager.instance = new TestAuthenticationManager();
}
return TestAuthenticationManager.instance;
}
private static instance: TestAuthenticationManager;
private constructor() {
// do something construct...
}
fetch(input: RequestInfo, options: {} = {}): Promise<Response> {
return solidAuthClientCLI.fetch(input, options);
}
login(options: {}): Promise<any> {
return solidAuthClientCLI.login(options);
}
async currentSession(): Promise<any> {
return solidAuthClientCLI.currentSession();
}
}
let StorageAuthenticationManager = AuthenticationManager.getInstance();
let StorageTestAuthenticationManager = TestAuthenticationManager.getInstance();
export {
solidAuthClient,
StorageAuthenticationManager,
StorageTestAuthenticationManager
};