@or-sdk/auth 0.25.0-beta.631.0 → 0.25.0
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/CHANGELOG.md +82 -0
- package/dist/cjs/Auth.js +9 -3
- package/dist/cjs/Auth.js.map +1 -1
- package/dist/esm/Auth.js +315 -350
- package/dist/esm/Auth.js.map +1 -1
- package/dist/esm/utils/NoRightsError.js +0 -1
- package/dist/esm/utils/NoRightsError.js.map +1 -1
- package/dist/esm/utils/generateFingerPrint.js +12 -3
- package/dist/esm/utils/generateFingerPrint.js.map +1 -1
- package/dist/types/Auth.d.ts +8 -7
- package/dist/types/Auth.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -4
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/Auth.ts +19 -7
- package/src/types.ts +6 -4
- package/tsconfig.esm.json +1 -1
package/dist/esm/Auth.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import axios from 'axios';
|
|
2
11
|
import { Settings } from '@or-sdk/settings';
|
|
3
12
|
import { SdkApi } from '@or-sdk/sdk-api';
|
|
@@ -9,27 +18,12 @@ const defaultCookiePollingInterval = 500;
|
|
|
9
18
|
const defaultExpireInShort = 3600000;
|
|
10
19
|
const defaultExpireInLong = 30758400000;
|
|
11
20
|
export class Auth {
|
|
12
|
-
discoveryUrl;
|
|
13
|
-
sdkUrl;
|
|
14
|
-
cookieDomain;
|
|
15
|
-
cookie;
|
|
16
|
-
userCookieName;
|
|
17
|
-
allowGuestLogin;
|
|
18
|
-
allowIframe;
|
|
19
|
-
deprecatedCookieName;
|
|
20
|
-
deprecatedUserExpireCookieName;
|
|
21
|
-
deprecatedDomain;
|
|
22
|
-
multiUserCookieName;
|
|
23
|
-
userExpireCookieName;
|
|
24
|
-
cookiePollingInterval;
|
|
25
|
-
expireInShort;
|
|
26
|
-
expireInLong;
|
|
27
|
-
loggedIn = false;
|
|
28
|
-
monitorCookieTimeout;
|
|
29
21
|
constructor(params) {
|
|
30
|
-
|
|
22
|
+
this.loggedIn = false;
|
|
23
|
+
const { discoveryUrl, sdkUrl, cookieDomain, allowGuestLogin, userCookieName, userExpireCookieName, cookiePrefix, multiUserCookieName, cookiePollingInterval, expireInShort, expireInLong, allowIframe, authUiUrl, } = params;
|
|
31
24
|
this.discoveryUrl = discoveryUrl;
|
|
32
25
|
this.sdkUrl = sdkUrl;
|
|
26
|
+
this.authUiUrl = authUiUrl;
|
|
33
27
|
this.cookie = new Cookie();
|
|
34
28
|
this.cookieDomain = cookieDomain;
|
|
35
29
|
this.allowGuestLogin = Boolean(allowGuestLogin);
|
|
@@ -85,38 +79,13 @@ export class Auth {
|
|
|
85
79
|
}
|
|
86
80
|
_saveCookies(user, expireIn) {
|
|
87
81
|
const nextExpiration = this._getNextExpiration(expireIn);
|
|
88
|
-
this.cookie.set(this.userCookieName, user, {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
sameSite: this.allowIframe ? 'none' : 'lax',
|
|
93
|
-
...this.domain,
|
|
94
|
-
});
|
|
95
|
-
this.cookie.set(this.userExpireCookieName, expireIn, {
|
|
96
|
-
path: '/',
|
|
97
|
-
expires: nextExpiration,
|
|
98
|
-
secure: true,
|
|
99
|
-
sameSite: this.allowIframe ? 'none' : 'lax',
|
|
100
|
-
...this.domain,
|
|
101
|
-
});
|
|
102
|
-
this.cookie.set(this.deprecatedCookieName, user, {
|
|
103
|
-
path: '/',
|
|
104
|
-
expires: nextExpiration,
|
|
105
|
-
...this.domain,
|
|
106
|
-
});
|
|
107
|
-
this.cookie.set(this.deprecatedUserExpireCookieName, expireIn, {
|
|
108
|
-
path: '/',
|
|
109
|
-
expires: nextExpiration,
|
|
110
|
-
...this.domain,
|
|
111
|
-
});
|
|
82
|
+
this.cookie.set(this.userCookieName, user, Object.assign({ path: '/', expires: nextExpiration, secure: true, sameSite: this.allowIframe ? 'none' : 'lax' }, this.domain));
|
|
83
|
+
this.cookie.set(this.userExpireCookieName, expireIn, Object.assign({ path: '/', expires: nextExpiration, secure: true, sameSite: this.allowIframe ? 'none' : 'lax' }, this.domain));
|
|
84
|
+
this.cookie.set(this.deprecatedCookieName, user, Object.assign({ path: '/', expires: nextExpiration }, this.domain));
|
|
85
|
+
this.cookie.set(this.deprecatedUserExpireCookieName, expireIn, Object.assign({ path: '/', expires: nextExpiration }, this.domain));
|
|
112
86
|
}
|
|
113
87
|
saveMultiUser(user, expiration) {
|
|
114
|
-
this.cookie.set(this.multiUserCookieName, user, {
|
|
115
|
-
path: '/',
|
|
116
|
-
expires: this._getNextExpiration(expiration),
|
|
117
|
-
secure: true,
|
|
118
|
-
...this.domain,
|
|
119
|
-
});
|
|
88
|
+
this.cookie.set(this.multiUserCookieName, user, Object.assign({ path: '/', expires: this._getNextExpiration(expiration), secure: true }, this.domain));
|
|
120
89
|
}
|
|
121
90
|
updateCookieExpiration() {
|
|
122
91
|
const user = this._getUser;
|
|
@@ -134,356 +103,352 @@ export class Auth {
|
|
|
134
103
|
throw new NoRightsError('Authorization for guests is not allowed');
|
|
135
104
|
}
|
|
136
105
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
106
|
+
saveUser({ long, user }) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const key = long ? 'cookieExpirationLong' : 'cookieExpirationShort';
|
|
109
|
+
const settingsApi = new Settings({
|
|
110
|
+
token: user.token,
|
|
111
|
+
discoveryUrl: this.discoveryUrl,
|
|
112
|
+
sdkUrl: this.sdkUrl,
|
|
113
|
+
});
|
|
114
|
+
let cookieExpirationDuration;
|
|
115
|
+
try {
|
|
116
|
+
cookieExpirationDuration = yield settingsApi.getMergedSettings({ key });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.log('Unable to fetch settingCookiesExpire from user Settings: ', error);
|
|
120
|
+
}
|
|
121
|
+
if (!cookieExpirationDuration) {
|
|
122
|
+
cookieExpirationDuration = long ? this.expireInLong : this.expireInShort;
|
|
123
|
+
}
|
|
124
|
+
this._saveCookies(user, cookieExpirationDuration);
|
|
143
125
|
});
|
|
144
|
-
let cookieExpirationDuration;
|
|
145
|
-
try {
|
|
146
|
-
cookieExpirationDuration = await settingsApi.getMergedSettings({ key });
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
console.log('Unable to fetch settingCookiesExpire from user Settings: ', error);
|
|
150
|
-
}
|
|
151
|
-
if (!cookieExpirationDuration) {
|
|
152
|
-
cookieExpirationDuration = long ? this.expireInLong : this.expireInShort;
|
|
153
|
-
}
|
|
154
|
-
this._saveCookies(user, cookieExpirationDuration);
|
|
155
126
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
user,
|
|
186
|
-
});
|
|
127
|
+
signIn({ credentials, long, allowGuestLogin = false, captchaToken, isCaptchaV2Checkbox, verificationCode, userToken, rememberTwoFactor, }) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const fingerPrint = yield generateFingerPrint();
|
|
130
|
+
const options = Object.assign(Object.assign(Object.assign({}, credentials), { captchaToken,
|
|
131
|
+
isCaptchaV2Checkbox,
|
|
132
|
+
verificationCode,
|
|
133
|
+
fingerPrint,
|
|
134
|
+
rememberTwoFactor }), userToken ? { userToken } : {});
|
|
135
|
+
const sdkApi = new SdkApi({
|
|
136
|
+
token: '',
|
|
137
|
+
discoveryUrl: this.discoveryUrl,
|
|
138
|
+
sdkUrl: this.sdkUrl,
|
|
139
|
+
});
|
|
140
|
+
const user = yield sdkApi.makeRequest({
|
|
141
|
+
method: 'POST',
|
|
142
|
+
route: '/auth/token',
|
|
143
|
+
data: options,
|
|
144
|
+
});
|
|
145
|
+
this._validateGuest(user.role, allowGuestLogin);
|
|
146
|
+
if (!user.twoFactorCheck && !user.captchaCheck) {
|
|
147
|
+
if (user.tokenType === 'multi-user') {
|
|
148
|
+
this.saveMultiUser(user, long ? this.expireInLong : this.expireInShort);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
yield this.saveUser({
|
|
152
|
+
long,
|
|
153
|
+
user,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
187
156
|
}
|
|
188
|
-
|
|
189
|
-
|
|
157
|
+
return user;
|
|
158
|
+
});
|
|
190
159
|
}
|
|
191
160
|
_checkDeprecatedCookies() {
|
|
192
161
|
const user = this.cookie.get(this.deprecatedCookieName);
|
|
193
162
|
if (user) {
|
|
194
163
|
const deprecatedUserExpireValue = this.getUserExpire(this.deprecatedUserExpireCookieName);
|
|
195
164
|
const nextExpiration = this._getNextExpiration(deprecatedUserExpireValue);
|
|
196
|
-
this.cookie.set(this.userCookieName, user, {
|
|
197
|
-
|
|
198
|
-
expires: nextExpiration,
|
|
199
|
-
secure: true,
|
|
200
|
-
...this.domain,
|
|
201
|
-
});
|
|
202
|
-
this.cookie.set(this.userExpireCookieName, deprecatedUserExpireValue, {
|
|
203
|
-
path: '/',
|
|
204
|
-
expires: nextExpiration,
|
|
205
|
-
secure: true,
|
|
206
|
-
...this.domain,
|
|
207
|
-
});
|
|
165
|
+
this.cookie.set(this.userCookieName, user, Object.assign({ path: '/', expires: nextExpiration, secure: true }, this.domain));
|
|
166
|
+
this.cookie.set(this.userExpireCookieName, deprecatedUserExpireValue, Object.assign({ path: '/', expires: nextExpiration, secure: true }, this.domain));
|
|
208
167
|
}
|
|
209
168
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
169
|
+
_validateToken(token, allowGuestLogin = false) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const sdkApi = new SdkApi({
|
|
172
|
+
token,
|
|
173
|
+
discoveryUrl: this.discoveryUrl,
|
|
174
|
+
sdkUrl: this.sdkUrl,
|
|
175
|
+
});
|
|
176
|
+
const user = yield sdkApi.makeRequest({
|
|
177
|
+
method: 'GET',
|
|
178
|
+
route: '/auth/token',
|
|
179
|
+
});
|
|
180
|
+
this._validateGuest(user.role, allowGuestLogin);
|
|
181
|
+
return user;
|
|
219
182
|
});
|
|
220
|
-
this._validateGuest(user.role, allowGuestLogin);
|
|
221
|
-
return user;
|
|
222
183
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
return user;
|
|
184
|
+
signInWithToken(token, allowGuestLogin = false, shouldNotSaveCookies = false) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
let userInfo = {};
|
|
187
|
+
if (_.isObject(token)) {
|
|
188
|
+
allowGuestLogin = _.get(token, 'allowGuestLogin', false);
|
|
189
|
+
shouldNotSaveCookies = _.get(token, 'shouldNotSaveCookies', false);
|
|
190
|
+
userInfo = _.get(token, 'userInfo', {});
|
|
191
|
+
token = token.token;
|
|
192
|
+
}
|
|
193
|
+
if (!token) {
|
|
194
|
+
return Promise.reject(new Error('No token given'));
|
|
195
|
+
}
|
|
196
|
+
this._checkDeprecatedCookies();
|
|
197
|
+
const user = yield this._validateToken(token, allowGuestLogin);
|
|
198
|
+
_.assign(user, { token });
|
|
199
|
+
const allow = _.get(user, 'allow', false);
|
|
200
|
+
if (!allow) {
|
|
201
|
+
throw Error('Invalid Token');
|
|
202
|
+
}
|
|
203
|
+
if (!shouldNotSaveCookies) {
|
|
204
|
+
this._saveCookies(Object.assign(Object.assign({}, userInfo), user), this.getUserExpire());
|
|
205
|
+
}
|
|
206
|
+
return user;
|
|
207
|
+
});
|
|
248
208
|
}
|
|
249
209
|
get multiUserHeaders() {
|
|
250
210
|
const { token = '' } = this.cookie.get(this.multiUserCookieName) || {};
|
|
251
211
|
return { headers: { Authorization: token } };
|
|
252
212
|
}
|
|
253
213
|
removeCookies() {
|
|
254
|
-
this.cookie.remove(this.userExpireCookieName, {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
});
|
|
258
|
-
this.cookie.remove(this.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
});
|
|
262
|
-
this.cookie.remove(this.multiUserCookieName, {
|
|
263
|
-
path: '/',
|
|
264
|
-
...this.domain,
|
|
265
|
-
});
|
|
266
|
-
this.cookie.remove(this.deprecatedCookieName, {
|
|
267
|
-
path: '/',
|
|
268
|
-
...this.domain,
|
|
269
|
-
});
|
|
270
|
-
this.cookie.remove(this.deprecatedUserExpireCookieName, {
|
|
271
|
-
path: '/',
|
|
272
|
-
...this.domain,
|
|
273
|
-
});
|
|
274
|
-
this.cookie.remove(this.deprecatedCookieName, {
|
|
275
|
-
path: '/',
|
|
276
|
-
...this.domain,
|
|
277
|
-
});
|
|
278
|
-
this.cookie.remove(this.deprecatedUserExpireCookieName, {
|
|
279
|
-
path: '/',
|
|
280
|
-
...this.domain,
|
|
281
|
-
});
|
|
214
|
+
this.cookie.remove(this.userExpireCookieName, Object.assign({ path: '/' }, this.domain));
|
|
215
|
+
this.cookie.remove(this.userCookieName, Object.assign({ path: '/' }, this.domain));
|
|
216
|
+
this.cookie.remove(this.multiUserCookieName, Object.assign({ path: '/' }, this.domain));
|
|
217
|
+
this.cookie.remove(this.deprecatedCookieName, Object.assign({ path: '/' }, this.domain));
|
|
218
|
+
this.cookie.remove(this.deprecatedUserExpireCookieName, Object.assign({ path: '/' }, this.domain));
|
|
219
|
+
this.cookie.remove(this.deprecatedCookieName, Object.assign({ path: '/' }, this.domain));
|
|
220
|
+
this.cookie.remove(this.deprecatedUserExpireCookieName, Object.assign({ path: '/' }, this.domain));
|
|
282
221
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
222
|
+
signOut(token) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
try {
|
|
225
|
+
const promises = [];
|
|
226
|
+
if (token) {
|
|
227
|
+
const sdkApi = new SdkApi({
|
|
228
|
+
token,
|
|
229
|
+
discoveryUrl: this.discoveryUrl,
|
|
230
|
+
sdkUrl: this.sdkUrl,
|
|
231
|
+
});
|
|
232
|
+
promises.push(sdkApi.makeRequest({
|
|
233
|
+
method: 'DELETE',
|
|
234
|
+
route: '/auth/fingerprint-token',
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
if (this.multiUserHeaders.headers.Authorization) {
|
|
238
|
+
const sdkApi = new SdkApi({
|
|
239
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
240
|
+
discoveryUrl: this.discoveryUrl,
|
|
241
|
+
sdkUrl: this.sdkUrl,
|
|
242
|
+
});
|
|
243
|
+
promises.push(sdkApi.makeRequest({
|
|
244
|
+
method: 'DELETE',
|
|
245
|
+
route: '/multi-user/fingerprint-token',
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
yield Promise.all(promises);
|
|
296
249
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
token: this.multiUserHeaders.headers.Authorization,
|
|
300
|
-
discoveryUrl: this.discoveryUrl,
|
|
301
|
-
sdkUrl: this.sdkUrl,
|
|
302
|
-
});
|
|
303
|
-
promises.push(sdkApi.makeRequest({
|
|
304
|
-
method: 'DELETE',
|
|
305
|
-
route: '/multi-user/fingerprint-token',
|
|
306
|
-
}));
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.log('Logout failed: ', error);
|
|
307
252
|
}
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
catch (error) {
|
|
311
|
-
console.log('Logout failed: ', error);
|
|
312
|
-
}
|
|
313
|
-
this.removeCookies();
|
|
253
|
+
this.removeCookies();
|
|
254
|
+
});
|
|
314
255
|
}
|
|
315
|
-
|
|
316
|
-
this
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
user.identityProvider
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
256
|
+
validateUser(allowGuestLogin = false, shouldNotSaveCookies = false) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
this._checkDeprecatedCookies();
|
|
259
|
+
const userParams = this._getUser;
|
|
260
|
+
if (!userParams) {
|
|
261
|
+
return Promise.reject(new Error('No cached user params are available'));
|
|
262
|
+
}
|
|
263
|
+
const user = yield this._validateToken(userParams.token, allowGuestLogin);
|
|
264
|
+
if (!user.identityProvider && userParams.identityProvider) {
|
|
265
|
+
user.identityProvider = userParams.identityProvider;
|
|
266
|
+
}
|
|
267
|
+
_.assign(user, { token: userParams.token });
|
|
268
|
+
const allow = _.get(user, 'allow', false);
|
|
269
|
+
if (!allow) {
|
|
270
|
+
throw Error('Invalid Token');
|
|
271
|
+
}
|
|
272
|
+
if (shouldNotSaveCookies)
|
|
273
|
+
return user;
|
|
274
|
+
const _user = Object.assign(Object.assign({}, userParams), { role: user.role, twoFactorenabled: user.twoFactorEnabled });
|
|
275
|
+
this._saveCookies(_user, this.getUserExpire());
|
|
276
|
+
return user;
|
|
277
|
+
});
|
|
331
278
|
}
|
|
332
279
|
hasUserParams() {
|
|
333
280
|
return Boolean(this._getUser);
|
|
334
281
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
282
|
+
multiUserGetUsersList() {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
if (!this.multiUserHeaders.headers.Authorization)
|
|
285
|
+
return false;
|
|
286
|
+
const sdkApi = new SdkApi({
|
|
287
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
288
|
+
discoveryUrl: this.discoveryUrl,
|
|
289
|
+
sdkUrl: this.sdkUrl,
|
|
290
|
+
});
|
|
291
|
+
return sdkApi.makeRequest({
|
|
292
|
+
method: 'GET',
|
|
293
|
+
route: '/multi-user/list-users',
|
|
294
|
+
});
|
|
346
295
|
});
|
|
347
296
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
297
|
+
multiUserLoginUser({ accountId, id, long }) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
const sdkApi = new SdkApi({
|
|
300
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
301
|
+
discoveryUrl: this.discoveryUrl,
|
|
302
|
+
sdkUrl: this.sdkUrl,
|
|
303
|
+
});
|
|
304
|
+
const user = yield sdkApi.makeRequest({
|
|
305
|
+
method: 'POST',
|
|
306
|
+
route: '/multi-user/user-token',
|
|
307
|
+
data: {
|
|
308
|
+
accountId,
|
|
309
|
+
id,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
yield this.saveUser({
|
|
313
|
+
long,
|
|
314
|
+
user,
|
|
315
|
+
});
|
|
316
|
+
return user;
|
|
361
317
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
318
|
+
}
|
|
319
|
+
getUserNameForLockScreen(user) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
const multiUserCookie = this.cookie.get(this.multiUserCookieName) || {};
|
|
322
|
+
if (multiUserCookie.username)
|
|
323
|
+
return multiUserCookie.username;
|
|
324
|
+
const { multiUserId, username, token } = user;
|
|
325
|
+
if (multiUserId) {
|
|
326
|
+
const sdkApi = new SdkApi({
|
|
327
|
+
token: token,
|
|
328
|
+
discoveryUrl: this.discoveryUrl,
|
|
329
|
+
sdkUrl: this.sdkUrl,
|
|
330
|
+
});
|
|
331
|
+
const { username } = yield sdkApi.makeRequest({
|
|
332
|
+
method: 'GET',
|
|
333
|
+
route: '/user/multi-user',
|
|
334
|
+
});
|
|
335
|
+
return username;
|
|
336
|
+
}
|
|
337
|
+
return username;
|
|
365
338
|
});
|
|
366
|
-
return user;
|
|
367
339
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (multiUserCookie.username)
|
|
371
|
-
return multiUserCookie.username;
|
|
372
|
-
const { multiUserId, username, token } = user;
|
|
373
|
-
if (multiUserId) {
|
|
340
|
+
multiUserGetProfile() {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
374
342
|
const sdkApi = new SdkApi({
|
|
375
|
-
token:
|
|
343
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
376
344
|
discoveryUrl: this.discoveryUrl,
|
|
377
345
|
sdkUrl: this.sdkUrl,
|
|
378
346
|
});
|
|
379
|
-
|
|
347
|
+
return sdkApi.makeRequest({
|
|
380
348
|
method: 'GET',
|
|
381
|
-
route: '/
|
|
349
|
+
route: '/multi-user/profile',
|
|
382
350
|
});
|
|
383
|
-
return username;
|
|
384
|
-
}
|
|
385
|
-
return username;
|
|
386
|
-
}
|
|
387
|
-
async multiUserGetProfile() {
|
|
388
|
-
const sdkApi = new SdkApi({
|
|
389
|
-
token: this.multiUserHeaders.headers.Authorization,
|
|
390
|
-
discoveryUrl: this.discoveryUrl,
|
|
391
|
-
sdkUrl: this.sdkUrl,
|
|
392
|
-
});
|
|
393
|
-
return sdkApi.makeRequest({
|
|
394
|
-
method: 'GET',
|
|
395
|
-
route: '/multi-user/profile',
|
|
396
351
|
});
|
|
397
352
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
353
|
+
multiUserSetProfile(profile) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
+
const sdkApi = new SdkApi({
|
|
356
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
357
|
+
discoveryUrl: this.discoveryUrl,
|
|
358
|
+
sdkUrl: this.sdkUrl,
|
|
359
|
+
});
|
|
360
|
+
return sdkApi.makeRequest({
|
|
361
|
+
method: 'POST',
|
|
362
|
+
route: '/multi-user/profile',
|
|
363
|
+
data: profile,
|
|
364
|
+
});
|
|
408
365
|
});
|
|
409
366
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
367
|
+
validateMultiUserToken() {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
const sdkApi = new SdkApi({
|
|
370
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
371
|
+
discoveryUrl: this.discoveryUrl,
|
|
372
|
+
sdkUrl: this.sdkUrl,
|
|
373
|
+
});
|
|
374
|
+
return sdkApi.makeRequest({
|
|
375
|
+
method: 'GET',
|
|
376
|
+
route: '/multi-user/token',
|
|
377
|
+
});
|
|
419
378
|
});
|
|
420
379
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const data = await sdkApi.makeRequest({
|
|
428
|
-
method: 'POST',
|
|
429
|
-
route: '/multi-user/sign-upload-url',
|
|
430
|
-
data: {
|
|
431
|
-
name,
|
|
432
|
-
contentType,
|
|
433
|
-
cacheControl,
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
const FormDataLib = isNode ? require('form-data') : FormData;
|
|
437
|
-
const formData = new FormDataLib();
|
|
438
|
-
_.forEach(data.uploadParams.fields, (value, key) => {
|
|
439
|
-
formData.append(key, value);
|
|
440
|
-
});
|
|
441
|
-
formData.append('cache-control', cacheControl);
|
|
442
|
-
formData.append('content-type', contentType);
|
|
443
|
-
formData.append('File', file, name);
|
|
444
|
-
if (isNode) {
|
|
445
|
-
await new Promise((resolve, reject) => {
|
|
446
|
-
formData.submit(data.uploadParams.url, (error) => {
|
|
447
|
-
if (error)
|
|
448
|
-
return reject(error);
|
|
449
|
-
resolve();
|
|
450
|
-
});
|
|
380
|
+
multiUserUploadIcon({ name, contentType, cacheControl = 'no-cache', file }) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
const sdkApi = new SdkApi({
|
|
383
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
384
|
+
discoveryUrl: this.discoveryUrl,
|
|
385
|
+
sdkUrl: this.sdkUrl,
|
|
451
386
|
});
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
387
|
+
const data = yield sdkApi.makeRequest({
|
|
388
|
+
method: 'POST',
|
|
389
|
+
route: '/multi-user/sign-upload-url',
|
|
390
|
+
data: {
|
|
391
|
+
name,
|
|
392
|
+
contentType,
|
|
393
|
+
cacheControl,
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
const FormDataLib = isNode ? require('form-data') : FormData;
|
|
397
|
+
const formData = new FormDataLib();
|
|
398
|
+
_.forEach(data.uploadParams.fields, (value, key) => {
|
|
399
|
+
formData.append(key, value);
|
|
400
|
+
});
|
|
401
|
+
formData.append('cache-control', cacheControl);
|
|
402
|
+
formData.append('content-type', contentType);
|
|
403
|
+
formData.append('File', file, name);
|
|
404
|
+
if (isNode) {
|
|
405
|
+
yield new Promise((resolve, reject) => {
|
|
406
|
+
formData.submit(data.uploadParams.url, (error) => {
|
|
407
|
+
if (error)
|
|
408
|
+
return reject(error);
|
|
409
|
+
resolve();
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
yield axios.post(data.uploadParams.url, formData);
|
|
415
|
+
}
|
|
416
|
+
return data.downloadUrl;
|
|
470
417
|
});
|
|
471
418
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
419
|
+
confirmEmailChange({ token }) {
|
|
420
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
421
|
+
const sdkApi = new SdkApi({
|
|
422
|
+
token: '',
|
|
423
|
+
discoveryUrl: this.discoveryUrl,
|
|
424
|
+
sdkUrl: this.sdkUrl,
|
|
425
|
+
});
|
|
426
|
+
return sdkApi.makeRequest({
|
|
427
|
+
method: 'POST',
|
|
428
|
+
route: '/multi-user/change-email-finish',
|
|
429
|
+
data: {
|
|
430
|
+
token,
|
|
431
|
+
},
|
|
432
|
+
});
|
|
477
433
|
});
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
434
|
+
}
|
|
435
|
+
multiUserUpdateTwoFactor({ secret, enabled, codes, verificationCode }) {
|
|
436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
+
const sdkApi = new SdkApi({
|
|
438
|
+
token: this.multiUserHeaders.headers.Authorization,
|
|
439
|
+
discoveryUrl: this.discoveryUrl,
|
|
440
|
+
sdkUrl: this.sdkUrl,
|
|
441
|
+
});
|
|
442
|
+
return sdkApi.makeRequest({
|
|
443
|
+
method: 'POST',
|
|
444
|
+
route: '/multi-user/twofactor',
|
|
445
|
+
data: {
|
|
446
|
+
secret,
|
|
447
|
+
enabled,
|
|
448
|
+
codes,
|
|
449
|
+
verificationCode,
|
|
450
|
+
},
|
|
451
|
+
});
|
|
487
452
|
});
|
|
488
453
|
}
|
|
489
454
|
}
|