webledger-auth-plugin 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,6 +8,8 @@ declare module '@ioc:AuthService' {
|
|
|
8
8
|
resendEmailVerification(email: string): any;
|
|
9
9
|
verifyPin(uuid: string, user_pin: string): any;
|
|
10
10
|
forgotPin(uuid: string, password: string, user_pin: string): any;
|
|
11
|
+
createToken(sub: string): any;
|
|
12
|
+
verifyToken(token: string, sub?: string): any;
|
|
11
13
|
}
|
|
12
14
|
const authService: AuthServiceI;
|
|
13
15
|
export default authService;
|
|
@@ -4,6 +4,8 @@ export default class AuthService implements AuthServiceI {
|
|
|
4
4
|
private client;
|
|
5
5
|
private paths;
|
|
6
6
|
constructor(config: AuthServiceConfig);
|
|
7
|
+
createToken(sub: string): any;
|
|
8
|
+
verifyToken(token: string, sub?: string): any;
|
|
7
9
|
private setAuthToken;
|
|
8
10
|
login(email: string, password: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
11
|
signup(params: any): Promise<import("axios").AxiosResponse<any, any>>;
|
package/build/src/AuthService.js
CHANGED
|
@@ -30,11 +30,25 @@ class AuthService {
|
|
|
30
30
|
}
|
|
31
31
|
this.paths = { ...this.paths, ...config.paths };
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
createToken(sub) {
|
|
34
34
|
const payload = { env: this.config.env, type: this.config.type, iss: this.config.iss, sub };
|
|
35
35
|
const jwtAuthToken = (0, jsonwebtoken_1.sign)(payload, this.config.secret, {
|
|
36
36
|
expiresIn: this.config.expiry || '1m',
|
|
37
37
|
});
|
|
38
|
+
return jwtAuthToken;
|
|
39
|
+
}
|
|
40
|
+
verifyToken(token, sub) {
|
|
41
|
+
const data = (0, jsonwebtoken_1.verify)(token, this.config.secret);
|
|
42
|
+
if (sub) {
|
|
43
|
+
if (sub === data.sub) {
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
setAuthToken(sub) {
|
|
51
|
+
const jwtAuthToken = this.createToken(sub);
|
|
38
52
|
this.client.defaults.headers.common['Authorization'] = `Bearer ${jwtAuthToken}`;
|
|
39
53
|
}
|
|
40
54
|
login(email, password) {
|