@cloudbase/oauth 3.0.0 → 3.0.1
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/dist/cjs/auth/apis.d.ts +22 -4
- package/dist/cjs/auth/apis.js +255 -66
- package/dist/cjs/auth/auth-error.d.ts +6 -0
- package/dist/cjs/auth/auth-error.js +32 -0
- package/dist/cjs/auth/consts.d.ts +22 -0
- package/dist/cjs/auth/consts.js +24 -2
- package/dist/cjs/auth/models.d.ts +13 -4
- package/dist/cjs/auth/models.js +1 -1
- package/dist/cjs/captcha/captcha-dom.d.ts +3 -0
- package/dist/cjs/captcha/captcha-dom.js +223 -0
- package/dist/cjs/captcha/captcha.d.ts +3 -1
- package/dist/cjs/captcha/captcha.js +11 -102
- package/dist/cjs/index.d.ts +12 -2
- package/dist/cjs/index.js +27 -4
- package/dist/cjs/oauth2client/interface.d.ts +1 -1
- package/dist/cjs/oauth2client/interface.js +1 -1
- package/dist/cjs/oauth2client/models.d.ts +15 -1
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +62 -3
- package/dist/cjs/oauth2client/oauth2client.js +426 -131
- package/dist/cjs/utils/base64.d.ts +5 -0
- package/dist/cjs/utils/base64.js +15 -2
- package/dist/cjs/utils/encryptlong/index.js +22 -16
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/mp.js +4 -4
- package/dist/cjs/utils/urlSearchParams.js +1 -1
- package/dist/esm/auth/apis.d.ts +22 -4
- package/dist/esm/auth/apis.js +130 -10
- package/dist/esm/auth/auth-error.d.ts +6 -0
- package/dist/esm/auth/auth-error.js +9 -0
- package/dist/esm/auth/consts.d.ts +22 -0
- package/dist/esm/auth/consts.js +22 -0
- package/dist/esm/auth/models.d.ts +13 -4
- package/dist/esm/captcha/captcha-dom.d.ts +3 -0
- package/dist/esm/captcha/captcha-dom.js +129 -0
- package/dist/esm/captcha/captcha.d.ts +3 -1
- package/dist/esm/captcha/captcha.js +14 -97
- package/dist/esm/index.d.ts +12 -2
- package/dist/esm/index.js +20 -3
- package/dist/esm/oauth2client/interface.d.ts +1 -1
- package/dist/esm/oauth2client/models.d.ts +15 -1
- package/dist/esm/oauth2client/oauth2client.d.ts +62 -3
- package/dist/esm/oauth2client/oauth2client.js +200 -55
- package/dist/esm/utils/base64.d.ts +5 -0
- package/dist/esm/utils/base64.js +12 -0
- package/dist/esm/utils/encryptlong/index.js +21 -15
- package/dist/esm/utils/mp.js +3 -3
- package/dist/miniprogram/index.js +1 -1
- package/package.json +10 -4
- package/src/auth/apis.ts +222 -17
- package/src/auth/auth-error.ts +21 -0
- package/src/auth/consts.ts +28 -0
- package/src/auth/models.ts +13 -4
- package/src/captcha/captcha-dom.ts +178 -0
- package/src/captcha/captcha.ts +25 -114
- package/src/index.ts +54 -4
- package/src/oauth2client/interface.ts +1 -1
- package/src/oauth2client/models.ts +29 -1
- package/src/oauth2client/oauth2client.ts +308 -55
- package/src/utils/base64.ts +12 -0
- package/src/utils/encryptlong/index.js +20 -14
- package/src/utils/index.ts +1 -0
- package/src/utils/mp.ts +3 -3
- package/src/utils/urlSearchParams.ts +2 -0
- package/tsconfig.json +1 -0
- package/dist/cjs/utils/cloudbase-adapter-wx_mp.d.ts +0 -1
- package/dist/cjs/utils/cloudbase-adapter-wx_mp.js +0 -40
- package/dist/esm/utils/cloudbase-adapter-wx_mp.d.ts +0 -1
- package/dist/esm/utils/cloudbase-adapter-wx_mp.js +0 -35
- package/src/utils/cloudbase-adapter-wx_mp.ts +0 -42
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ErrorType } from './consts';
|
|
2
|
-
import { ApiUrls, ApiUrlsV2, AUTH_API_PREFIX } from '../auth/consts';
|
|
2
|
+
import { ApiUrls, ApiUrlsV2, AUTH_API_PREFIX, AUTH_STATE_CHANGED_TYPE, EVENTS } from '../auth/consts';
|
|
3
3
|
import { uuidv4 } from '../utils/uuid';
|
|
4
4
|
import { getPathName } from '../utils/index';
|
|
5
5
|
import { SinglePromise } from '../utils/function/single-promise';
|
|
6
6
|
import { weBtoa } from '../utils/base64';
|
|
7
|
-
import {
|
|
7
|
+
import { isMp } from '../utils/mp';
|
|
8
8
|
import { langEvent } from '@cloudbase/utilities';
|
|
9
9
|
const RequestIdHeaderName = 'x-request-id';
|
|
10
10
|
const DeviceIdHeaderName = 'x-device-id';
|
|
@@ -103,15 +103,13 @@ function isCredentialsExpired(credentials) {
|
|
|
103
103
|
class LocalCredentials {
|
|
104
104
|
constructor(options) {
|
|
105
105
|
this.credentials = null;
|
|
106
|
+
this.accessKeyCredentials = null;
|
|
106
107
|
this.singlePromise = null;
|
|
107
108
|
this.tokenSectionName = options.tokenSectionName;
|
|
108
109
|
this.storage = options.storage;
|
|
109
110
|
this.clientId = options.clientId;
|
|
110
111
|
this.singlePromise = new SinglePromise({ clientId: this.clientId });
|
|
111
112
|
this.credentials = options.credentials || null;
|
|
112
|
-
if (this.credentials) {
|
|
113
|
-
this.setCredentials(this.credentials);
|
|
114
|
-
}
|
|
115
113
|
}
|
|
116
114
|
getStorageCredentialsSync() {
|
|
117
115
|
let credentials = null;
|
|
@@ -148,10 +146,17 @@ class LocalCredentials {
|
|
|
148
146
|
this.credentials = null;
|
|
149
147
|
}
|
|
150
148
|
}
|
|
149
|
+
setAccessKeyCredentials(credentials) {
|
|
150
|
+
this.accessKeyCredentials = credentials;
|
|
151
|
+
}
|
|
151
152
|
async getCredentials() {
|
|
152
153
|
return this.singlePromise.run('getCredentials', async () => {
|
|
153
154
|
if (isCredentialsExpired(this.credentials)) {
|
|
154
|
-
|
|
155
|
+
const { credentials, isAccessKeyCredentials } = await this.getStorageCredentials();
|
|
156
|
+
if (isAccessKeyCredentials) {
|
|
157
|
+
return credentials;
|
|
158
|
+
}
|
|
159
|
+
this.credentials = credentials;
|
|
155
160
|
}
|
|
156
161
|
return this.credentials;
|
|
157
162
|
});
|
|
@@ -159,8 +164,9 @@ class LocalCredentials {
|
|
|
159
164
|
async getStorageCredentials() {
|
|
160
165
|
return this.singlePromise.run('_getStorageCredentials', async () => {
|
|
161
166
|
let credentials = null;
|
|
167
|
+
let isAccessKeyCredentials = false;
|
|
162
168
|
const tokenStr = await this.storage.getItem(this.tokenSectionName);
|
|
163
|
-
if (tokenStr
|
|
169
|
+
if (!!tokenStr) {
|
|
164
170
|
try {
|
|
165
171
|
credentials = JSON.parse(tokenStr);
|
|
166
172
|
if (credentials?.expires_at) {
|
|
@@ -172,12 +178,19 @@ class LocalCredentials {
|
|
|
172
178
|
credentials = null;
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
|
-
|
|
181
|
+
else {
|
|
182
|
+
credentials = this.accessKeyCredentials || null;
|
|
183
|
+
isAccessKeyCredentials = true;
|
|
184
|
+
}
|
|
185
|
+
return { credentials, isAccessKeyCredentials };
|
|
176
186
|
});
|
|
177
187
|
}
|
|
178
188
|
}
|
|
179
189
|
class OAuth2Client {
|
|
180
190
|
constructor(options) {
|
|
191
|
+
this.initializePromise = null;
|
|
192
|
+
this.lockAcquired = false;
|
|
193
|
+
this.pendingInLock = [];
|
|
181
194
|
this.singlePromise = null;
|
|
182
195
|
if (!options.clientSecret) {
|
|
183
196
|
options.clientSecret = '';
|
|
@@ -189,7 +202,7 @@ class OAuth2Client {
|
|
|
189
202
|
this.apiPath = options.apiPath || AUTH_API_PREFIX;
|
|
190
203
|
this.clientId = options.clientId;
|
|
191
204
|
this.i18n = options.i18n;
|
|
192
|
-
this.
|
|
205
|
+
this.eventBus = options.eventBus;
|
|
193
206
|
this.singlePromise = new SinglePromise({ clientId: this.clientId });
|
|
194
207
|
this.retry = this.formatRetry(options.retry, OAuth2Client.defaultRetry);
|
|
195
208
|
if (options.baseRequest) {
|
|
@@ -205,13 +218,6 @@ class OAuth2Client {
|
|
|
205
218
|
tokenSectionName: `credentials_${options.clientId}`,
|
|
206
219
|
storage: this.storage,
|
|
207
220
|
clientId: options.clientId,
|
|
208
|
-
credentials: this.publishable_key ? {
|
|
209
|
-
access_token: this.publishable_key,
|
|
210
|
-
token_type: 'Bearer',
|
|
211
|
-
scope: 'publishable_key',
|
|
212
|
-
expires_at: new Date(+new Date() + +new Date()),
|
|
213
|
-
expires_in: +new Date() + +new Date(),
|
|
214
|
-
} : null,
|
|
215
221
|
});
|
|
216
222
|
this.clientSecret = options.clientSecret;
|
|
217
223
|
if (options.clientId) {
|
|
@@ -219,9 +225,12 @@ class OAuth2Client {
|
|
|
219
225
|
}
|
|
220
226
|
this.wxCloud = options.wxCloud;
|
|
221
227
|
try {
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
this.wxCloud
|
|
228
|
+
if (isMp()) {
|
|
229
|
+
this.useWxCloud = options.useWxCloud;
|
|
230
|
+
if (this.wxCloud === undefined && options.env) {
|
|
231
|
+
wx.cloud.init({ env: options.env });
|
|
232
|
+
this.wxCloud = wx.cloud;
|
|
233
|
+
}
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
catch (error) {
|
|
@@ -229,14 +238,39 @@ class OAuth2Client {
|
|
|
229
238
|
this.refreshTokenFunc = options.refreshTokenFunc || this.defaultRefreshTokenFunc;
|
|
230
239
|
this.anonymousSignInFunc = options.anonymousSignInFunc;
|
|
231
240
|
this.onCredentialsError = options.onCredentialsError;
|
|
241
|
+
this.getInitialSession = options.getInitialSession;
|
|
242
|
+
this.onInitialSessionObtained = options.onInitialSessionObtained;
|
|
243
|
+
this.logDebugMessages = options.debug ?? false;
|
|
232
244
|
langEvent.bus.on(langEvent.LANG_CHANGE_EVENT, (params) => {
|
|
233
245
|
this.i18n = params.data?.i18n || this.i18n;
|
|
234
246
|
});
|
|
235
247
|
}
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
setGetInitialSession(callback) {
|
|
249
|
+
this.getInitialSession = callback;
|
|
250
|
+
}
|
|
251
|
+
setOnInitialSessionObtained(callback) {
|
|
252
|
+
this.onInitialSessionObtained = callback;
|
|
253
|
+
}
|
|
254
|
+
async initialize(func) {
|
|
255
|
+
if (this.initializePromise) {
|
|
256
|
+
return await this.initializePromise;
|
|
257
|
+
}
|
|
258
|
+
if (func !== undefined) {
|
|
259
|
+
this.initializePromise = func;
|
|
260
|
+
return await this.initializePromise;
|
|
261
|
+
}
|
|
262
|
+
this.initializePromise = (async () => await this._acquireLock(-1, async () => await this._initialize()))();
|
|
263
|
+
return await this.initializePromise;
|
|
264
|
+
}
|
|
265
|
+
async setCredentials(credentials) {
|
|
266
|
+
await this.initializePromise;
|
|
267
|
+
return this._acquireLock(-1, async () => this.localCredentials.setCredentials(credentials));
|
|
268
|
+
}
|
|
269
|
+
setAccessKeyCredentials(credentials) {
|
|
270
|
+
return this.localCredentials.setAccessKeyCredentials(credentials);
|
|
238
271
|
}
|
|
239
272
|
async getAccessToken() {
|
|
273
|
+
await this.initializePromise;
|
|
240
274
|
const credentials = await this.getCredentials();
|
|
241
275
|
if (credentials?.access_token) {
|
|
242
276
|
return Promise.resolve(credentials.access_token);
|
|
@@ -267,7 +301,7 @@ class OAuth2Client {
|
|
|
267
301
|
options.headers.Authorization = this.basicAuth;
|
|
268
302
|
}
|
|
269
303
|
if (options?.withCredentials) {
|
|
270
|
-
const credentials = await this.getCredentials();
|
|
304
|
+
const credentials = options.getCredentials ? await options.getCredentials() : await this.getCredentials();
|
|
271
305
|
if (credentials) {
|
|
272
306
|
if (this.tokenInURL) {
|
|
273
307
|
if (url.indexOf('?') < 0) {
|
|
@@ -293,12 +327,19 @@ class OAuth2Client {
|
|
|
293
327
|
const maxRequestTimes = retry + 1;
|
|
294
328
|
for (let requestTime = 0; requestTime < maxRequestTimes; requestTime++) {
|
|
295
329
|
try {
|
|
296
|
-
if (options.useWxCloud) {
|
|
330
|
+
if (options.useWxCloud || this.useWxCloud) {
|
|
297
331
|
response = await this.wxCloudCallFunction(url, options);
|
|
298
332
|
}
|
|
299
333
|
else {
|
|
300
334
|
response = await this.baseRequest(url, options);
|
|
301
335
|
}
|
|
336
|
+
if (!!response?.code) {
|
|
337
|
+
throw ({
|
|
338
|
+
error: response.code,
|
|
339
|
+
error_description: response.message,
|
|
340
|
+
error_uri: new URL(url).pathname,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
302
343
|
break;
|
|
303
344
|
}
|
|
304
345
|
catch (responseError) {
|
|
@@ -359,37 +400,8 @@ class OAuth2Client {
|
|
|
359
400
|
}
|
|
360
401
|
}
|
|
361
402
|
async getCredentials() {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const msg = 'credentials not found';
|
|
365
|
-
this.onCredentialsError?.({ msg });
|
|
366
|
-
return this.unAuthenticatedError(msg);
|
|
367
|
-
}
|
|
368
|
-
if (isCredentialsExpired(credentials)) {
|
|
369
|
-
if (credentials.refresh_token) {
|
|
370
|
-
try {
|
|
371
|
-
credentials = await this.refreshToken(credentials);
|
|
372
|
-
}
|
|
373
|
-
catch (error) {
|
|
374
|
-
if (credentials.scope === 'anonymous') {
|
|
375
|
-
credentials = await this.anonymousLogin(credentials);
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
this.onCredentialsError?.({ msg: error.error_description });
|
|
379
|
-
return Promise.reject(error);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else if (credentials.scope === 'anonymous') {
|
|
384
|
-
credentials = await this.anonymousLogin(credentials);
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
const msg = 'no refresh token found in credentials';
|
|
388
|
-
this.onCredentialsError?.({ msg });
|
|
389
|
-
return this.unAuthenticatedError(msg);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
return credentials;
|
|
403
|
+
await this.initializePromise;
|
|
404
|
+
return this._acquireLock(-1, async () => this._getCredentials());
|
|
393
405
|
}
|
|
394
406
|
getCredentialsSync() {
|
|
395
407
|
const credentials = this.localCredentials.getStorageCredentialsSync();
|
|
@@ -416,7 +428,11 @@ class OAuth2Client {
|
|
|
416
428
|
}
|
|
417
429
|
return credentials.groups;
|
|
418
430
|
}
|
|
419
|
-
async refreshToken(credentials) {
|
|
431
|
+
async refreshToken(credentials, options) {
|
|
432
|
+
await this.initializePromise;
|
|
433
|
+
return this._acquireLock(-1, async () => this._refreshToken(credentials, options));
|
|
434
|
+
}
|
|
435
|
+
async _refreshToken(credentials, options) {
|
|
420
436
|
return this.singlePromise.run('_refreshToken', async () => {
|
|
421
437
|
if (!credentials || !credentials.refresh_token) {
|
|
422
438
|
const msg = 'no refresh token found in credentials';
|
|
@@ -426,9 +442,13 @@ class OAuth2Client {
|
|
|
426
442
|
try {
|
|
427
443
|
const newCredentials = await this.refreshTokenFunc(credentials.refresh_token, credentials);
|
|
428
444
|
await this.localCredentials.setCredentials(newCredentials);
|
|
445
|
+
this.eventBus?.fire(EVENTS.AUTH_STATE_CHANGED, { event: AUTH_STATE_CHANGED_TYPE.TOKEN_REFRESHED });
|
|
429
446
|
return newCredentials;
|
|
430
447
|
}
|
|
431
448
|
catch (error) {
|
|
449
|
+
if (options?.throwError) {
|
|
450
|
+
throw error;
|
|
451
|
+
}
|
|
432
452
|
if (error.error === ErrorType.INVALID_GRANT) {
|
|
433
453
|
await this.localCredentials.setCredentials(null);
|
|
434
454
|
const msg = error.error_description;
|
|
@@ -541,6 +561,131 @@ class OAuth2Client {
|
|
|
541
561
|
};
|
|
542
562
|
return Promise.reject(respErr);
|
|
543
563
|
}
|
|
564
|
+
_debug(...args) {
|
|
565
|
+
if (this.logDebugMessages) {
|
|
566
|
+
console.log('[OAuth2Client]', ...args);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async _initialize() {
|
|
570
|
+
try {
|
|
571
|
+
if (!this.getInitialSession) {
|
|
572
|
+
this._debug('#_initialize()', 'no getInitialSession callback set, skipping');
|
|
573
|
+
return { error: null };
|
|
574
|
+
}
|
|
575
|
+
this._debug('#_initialize()', 'calling getInitialSession callback');
|
|
576
|
+
try {
|
|
577
|
+
const { data, error } = await this.getInitialSession();
|
|
578
|
+
if (data?.session) {
|
|
579
|
+
this._debug('#_initialize()', 'session obtained from getInitialSession', data.session);
|
|
580
|
+
await this.localCredentials.setCredentials(data?.session);
|
|
581
|
+
}
|
|
582
|
+
if (this.onInitialSessionObtained) {
|
|
583
|
+
this._debug('#_initialize()', 'calling onInitialSessionObtained callback');
|
|
584
|
+
try {
|
|
585
|
+
await this.onInitialSessionObtained(data, error);
|
|
586
|
+
}
|
|
587
|
+
catch (callbackError) {
|
|
588
|
+
this._debug('#_initialize()', 'error in onInitialSessionObtained', callbackError);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (error) {
|
|
592
|
+
this._debug('#_initialize()', 'error from getInitialSession', error);
|
|
593
|
+
return { error };
|
|
594
|
+
}
|
|
595
|
+
return { error: null };
|
|
596
|
+
}
|
|
597
|
+
catch (err) {
|
|
598
|
+
this._debug('#_initialize()', 'exception during getInitialSession', err);
|
|
599
|
+
return { error: err instanceof Error ? err : new Error(String(err)) };
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
this._debug('#_initialize()', 'unexpected error', error);
|
|
604
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
605
|
+
}
|
|
606
|
+
finally {
|
|
607
|
+
this._debug('#_initialize()', 'end');
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
async _acquireLock(acquireTimeout, fn) {
|
|
611
|
+
this._debug('#_acquireLock', 'begin', acquireTimeout);
|
|
612
|
+
try {
|
|
613
|
+
if (this.lockAcquired) {
|
|
614
|
+
const last = this.pendingInLock.length ? this.pendingInLock[this.pendingInLock.length - 1] : Promise.resolve();
|
|
615
|
+
const result = (async () => {
|
|
616
|
+
await last;
|
|
617
|
+
return await fn();
|
|
618
|
+
})();
|
|
619
|
+
this.pendingInLock.push((async () => {
|
|
620
|
+
try {
|
|
621
|
+
await result;
|
|
622
|
+
}
|
|
623
|
+
catch (_e) {
|
|
624
|
+
}
|
|
625
|
+
})());
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
this._debug('#_acquireLock', 'acquiring lock for client', this.clientId);
|
|
629
|
+
try {
|
|
630
|
+
this.lockAcquired = true;
|
|
631
|
+
const result = fn();
|
|
632
|
+
this.pendingInLock.push((async () => {
|
|
633
|
+
try {
|
|
634
|
+
await result;
|
|
635
|
+
}
|
|
636
|
+
catch (_e) {
|
|
637
|
+
}
|
|
638
|
+
})());
|
|
639
|
+
await result;
|
|
640
|
+
while (this.pendingInLock.length) {
|
|
641
|
+
const waitOn = [...this.pendingInLock];
|
|
642
|
+
await Promise.all(waitOn);
|
|
643
|
+
this.pendingInLock.splice(0, waitOn.length);
|
|
644
|
+
}
|
|
645
|
+
return await result;
|
|
646
|
+
}
|
|
647
|
+
finally {
|
|
648
|
+
this._debug('#_acquireLock', 'releasing lock for client', this.clientId);
|
|
649
|
+
this.lockAcquired = false;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
this._debug('#_acquireLock', 'end');
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async _getCredentials() {
|
|
657
|
+
let credentials = await this.localCredentials.getCredentials();
|
|
658
|
+
if (!credentials) {
|
|
659
|
+
const msg = 'credentials not found';
|
|
660
|
+
this.onCredentialsError?.({ msg });
|
|
661
|
+
return this.unAuthenticatedError(msg);
|
|
662
|
+
}
|
|
663
|
+
if (isCredentialsExpired(credentials)) {
|
|
664
|
+
if (credentials.refresh_token) {
|
|
665
|
+
try {
|
|
666
|
+
credentials = await this._refreshToken(credentials);
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
if (credentials.scope === 'anonymous') {
|
|
670
|
+
credentials = await this.anonymousLogin(credentials);
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
this.onCredentialsError?.({ msg: error.error_description });
|
|
674
|
+
return Promise.reject(error);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
else if (credentials.scope === 'anonymous') {
|
|
679
|
+
credentials = await this.anonymousLogin(credentials);
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
const msg = 'no refresh token found in credentials';
|
|
683
|
+
this.onCredentialsError?.({ msg });
|
|
684
|
+
return this.unAuthenticatedError(msg);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return credentials;
|
|
688
|
+
}
|
|
544
689
|
}
|
|
545
690
|
OAuth2Client.defaultRetry = 2;
|
|
546
691
|
OAuth2Client.minRetry = 0;
|
|
@@ -2,3 +2,8 @@ export declare function weBtoa(string: string): string;
|
|
|
2
2
|
export declare const weAtob: (string: string) => string;
|
|
3
3
|
export declare function base64_url_decode(str: string): string;
|
|
4
4
|
export declare function weappJwtDecode(token: string, options?: any): any;
|
|
5
|
+
export declare function weAppJwtDecodeAll(token: string): {
|
|
6
|
+
claims: any;
|
|
7
|
+
header: any;
|
|
8
|
+
signature: any;
|
|
9
|
+
};
|
package/dist/esm/utils/base64.js
CHANGED
|
@@ -89,3 +89,15 @@ export function weappJwtDecode(token, options) {
|
|
|
89
89
|
throw new Error(`Invalid token specified: ${e}` ? e.message : '');
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
export function weAppJwtDecodeAll(token) {
|
|
93
|
+
if (typeof token !== 'string') {
|
|
94
|
+
throw new Error('Invalid token specified');
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const parts = token.split('.').map((segment, i) => i === 2 ? segment : JSON.parse(base64_url_decode(segment)));
|
|
98
|
+
return { claims: parts[1], header: parts[0], signature: parts[2] };
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw new Error(`Invalid token specified: ${e}` ? e.message : '');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -2429,21 +2429,25 @@ if (!globalThis.IS_MP_BUILD) {
|
|
|
2429
2429
|
rng_pool = [];
|
|
2430
2430
|
rng_pptr = 0;
|
|
2431
2431
|
var t = void 0;
|
|
2432
|
-
if (window
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2432
|
+
if (typeof window !== 'undefined') {
|
|
2433
|
+
if (window?.crypto && window?.crypto.getRandomValues) {
|
|
2434
|
+
var z = new Uint32Array(256);
|
|
2435
|
+
window?.crypto.getRandomValues(z);
|
|
2436
|
+
for (t = 0; t < z.length; ++t) {
|
|
2437
|
+
rng_pool[rng_pptr++] = z[t] & 255;
|
|
2438
|
+
}
|
|
2437
2439
|
}
|
|
2438
2440
|
}
|
|
2439
2441
|
var onMouseMoveListener_1 = function (ev) {
|
|
2440
2442
|
this.count = this.count || 0;
|
|
2441
2443
|
if (this.count >= 256 || rng_pptr >= rng_psize) {
|
|
2442
|
-
if (window
|
|
2443
|
-
window?.removeEventListener
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
window?.detachEvent
|
|
2444
|
+
if (typeof window !== 'undefined') {
|
|
2445
|
+
if (window?.removeEventListener) {
|
|
2446
|
+
window?.removeEventListener('mousemove', onMouseMoveListener_1, false);
|
|
2447
|
+
}
|
|
2448
|
+
else if (window?.detachEvent) {
|
|
2449
|
+
window?.detachEvent('onmousemove', onMouseMoveListener_1);
|
|
2450
|
+
}
|
|
2447
2451
|
}
|
|
2448
2452
|
return;
|
|
2449
2453
|
}
|
|
@@ -2455,11 +2459,13 @@ if (!globalThis.IS_MP_BUILD) {
|
|
|
2455
2459
|
catch (e) {
|
|
2456
2460
|
}
|
|
2457
2461
|
};
|
|
2458
|
-
if (window
|
|
2459
|
-
window?.addEventListener
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
window?.attachEvent
|
|
2462
|
+
if (typeof window !== 'undefined') {
|
|
2463
|
+
if (window?.addEventListener) {
|
|
2464
|
+
window?.addEventListener('mousemove', onMouseMoveListener_1, false);
|
|
2465
|
+
}
|
|
2466
|
+
else if (window?.attachEvent) {
|
|
2467
|
+
window?.attachEvent('onmousemove', onMouseMoveListener_1);
|
|
2468
|
+
}
|
|
2463
2469
|
}
|
|
2464
2470
|
}
|
|
2465
2471
|
function rng_get_byte() {
|
package/dist/esm/utils/mp.js
CHANGED
|
@@ -9,7 +9,7 @@ export function isMp() {
|
|
|
9
9
|
if (globalThis.Page === undefined) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
if (!wx.
|
|
12
|
+
if (!wx.getDeviceInfo) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
if (!wx.getStorageSync) {
|
|
@@ -25,10 +25,10 @@ export function isMp() {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
|
-
if (!wx.
|
|
28
|
+
if (!wx.getDeviceInfo()) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
|
-
if (wx.
|
|
31
|
+
if (wx.getDeviceInfo().platform === 'qq') {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
}
|