-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authentication.js
63 lines (47 loc) · 1.59 KB
/
Authentication.js
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
const _ = require('lodash');
const PROVIDER = Symbol('provider');
const logger = require('@geek/logger').createLogger('@titanium/authentication', { meta: { filename: __filename } });
class Authentication {
constructor({ provider, options = {}} = {}) {
if (_.isNil(provider)) {
throw new Error('Must provide a valid Authentication service provider');
}
if (_.isString(provider)) {
this[PROVIDER] = new (require(provider))(options);
} else {
this[PROVIDER] = provider;
}
}
get token(){
return this[PROVIDER].token;
}
async authenticate(...args) {
logger.track('🔒 you are here → Authentication.authenticate');
return await this[PROVIDER].authenticate(...args);
}
async isAuthenticated(...args) {
logger.track('🔒 you are here → Authentication.isAuthenticated');
return await this[PROVIDER].isAuthenticated(...args);
}
async getAuthToken(...args) {
logger.track('🔒 you are here → Authentication.getAuthToken()');
return await this[provider].getAuthToken(...args);
}
async logout(...args) {
logger.track('🔒 you are here → Authentication.logout()');
return await this[PROVIDER].logout(...args);
}
async renew(...args) {
logger.track('🔒 you are here → Authentication.renew()');
return await this[PROVIDER].renew(...args);
}
static async getPublicKey(...args) {
logger.track(`🔒 you are here → Authentication.getPublicKey()`);
let public_key;
if (_.isFunction(this[PROVIDER].getPublicKey)) {
public_key = await this[PROVIDER].getPublicKey(...args);
}
return public_key;
}
}
module.exports = Authentication;