@gandalan/weblibs 1.1.80 → 1.1.82
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.
- package/api/fluentAuthBuilder.js +12 -6
- package/package.json +1 -1
package/api/fluentAuthBuilder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jwtDecode } from "jwt-decode";
|
|
2
2
|
import { isTokenValid, getRefreshToken } from "./fluentApi";
|
|
3
|
+
import validator from "validator";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @typedef {Object} FluentAuth
|
|
@@ -38,6 +39,11 @@ export function authBuilder() {
|
|
|
38
39
|
* @returns {FluentAuth}
|
|
39
40
|
*/
|
|
40
41
|
useAppToken(appToken = "") {
|
|
42
|
+
if (!validator.isUUID(appToken)) {
|
|
43
|
+
console.error("AppToken is not valid GUID");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
this.appToken = appToken; return this;
|
|
42
48
|
},
|
|
43
49
|
|
|
@@ -71,7 +77,7 @@ export function authBuilder() {
|
|
|
71
77
|
},
|
|
72
78
|
|
|
73
79
|
/**
|
|
74
|
-
* Authenticates the user with the JWT token or refreshes the token with
|
|
80
|
+
* Authenticates the user with the JWT token or refreshes the token with
|
|
75
81
|
* the refreshToken set before
|
|
76
82
|
* @return {string} the JWT token
|
|
77
83
|
*/
|
|
@@ -103,11 +109,11 @@ export function authBuilder() {
|
|
|
103
109
|
|
|
104
110
|
/**
|
|
105
111
|
* Login with credentials and return the JWT token
|
|
106
|
-
* @param {string} username
|
|
107
|
-
* @param {string} password
|
|
112
|
+
* @param {string} username
|
|
113
|
+
* @param {string} password
|
|
108
114
|
* @return {string} the JWT token
|
|
109
115
|
*/
|
|
110
|
-
async login(username = "", password = "")
|
|
116
|
+
async login(username = "", password = "")
|
|
111
117
|
{
|
|
112
118
|
if (username && password) {
|
|
113
119
|
const payload = { "Email": username, "Password": password, "AppToken": this.appToken };
|
|
@@ -153,7 +159,7 @@ export function authBuilder() {
|
|
|
153
159
|
{
|
|
154
160
|
this.token = await this.tryRefreshToken(this.refreshToken);
|
|
155
161
|
}
|
|
156
|
-
|
|
162
|
+
|
|
157
163
|
if (this.token && isTokenValid(this.token))
|
|
158
164
|
{
|
|
159
165
|
this.refreshToken = getRefreshToken(this.token);
|
|
@@ -173,7 +179,7 @@ export function authBuilder() {
|
|
|
173
179
|
// eslint-disable-next-line no-undef
|
|
174
180
|
globalThis.idasTokens = { token: this.token, refreshToken: this.refreshToken, appToken: this.appToken, userInfo };
|
|
175
181
|
},
|
|
176
|
-
|
|
182
|
+
|
|
177
183
|
/**
|
|
178
184
|
* Redirect to the login page
|
|
179
185
|
* @private
|