This repository was archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathauth.js
More file actions
61 lines (55 loc) · 1.43 KB
/
auth.js
File metadata and controls
61 lines (55 loc) · 1.43 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
51
52
53
54
55
56
57
58
59
60
61
class Authentication {
/**
* Creates an instance of the Authentication classs associated with the
* provided tokens and https worker.
*
* @param {*} httpsWorker
*/
constructor(httpsWorker) {
this.worker = httpsWorker;
}
/**
* Register a function to run on a certain event.
*
* @param {*} event The trigger for the function
* @param {*} handler event handler for the event
*/
on(event, handler) {
this.worker.on(event, handler);
}
/**
* Initialize the auth module with an existing state of tokens.
* The state provided should contain access, refresh, and expires properties.
*
* @param {*} state Pre-existing authentication state
*/
use(state) {
this.worker.tokens.store(state);
}
/**
* Snapshot of the current authentication tokens.
*/
tokens() {
return {
access: this.worker.tokens.access,
refresh: this.worker.tokens.refresh,
expires: this.worker.tokens.expires,
};
}
/**
* Attempts to establish a session for the provided email and password.
*
* @param {*} email emailed registered by the Wealthsimple Trade account
* @param {*} password The password of the account
*/
async login(email, password) {
return this.worker.login(email, password);
}
/**
* Generates a new set of access and refresh tokens.
*/
async refresh() {
return this.worker.refreshAuthentication();
}
}
export default Authentication;