@cloudbase/oauth 2.17.17 → 2.18.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/consts.d.ts +50 -49
- package/dist/cjs/auth/consts.js +52 -51
- package/dist/cjs/captcha/captcha.js +3 -3
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/oauth2client/oauth2client.d.ts +1 -0
- package/dist/cjs/oauth2client/oauth2client.js +70 -35
- package/dist/esm/auth/consts.d.ts +50 -49
- package/dist/esm/auth/consts.js +50 -49
- package/dist/esm/captcha/captcha.js +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/oauth2client/oauth2client.d.ts +1 -0
- package/dist/esm/oauth2client/oauth2client.js +26 -7
- package/dist/miniprogram/index.js +1 -1
- package/package.json +3 -3
- package/src/auth/consts.ts +51 -49
- package/src/captcha/captcha.ts +1 -1
- package/src/index.ts +1 -0
- package/src/oauth2client/oauth2client.ts +25 -7
|
@@ -502,15 +502,20 @@ export class OAuth2Client implements AuthClient {
|
|
|
502
502
|
return this.unAuthenticatedError('credentials not found')
|
|
503
503
|
}
|
|
504
504
|
if (isCredentialsExpired(credentials)) {
|
|
505
|
-
if (credentials
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
505
|
+
if (credentials.refresh_token) {
|
|
506
|
+
try {
|
|
507
|
+
credentials = await this.refreshToken(credentials)
|
|
508
|
+
} catch (error) {
|
|
509
|
+
if (credentials.scope === 'anonymous') {
|
|
510
|
+
credentials = await this.anonymousLogin(credentials)
|
|
511
|
+
} else {
|
|
512
|
+
return Promise.reject(error)
|
|
513
|
+
}
|
|
511
514
|
}
|
|
515
|
+
} else if (credentials.scope === 'anonymous') {
|
|
516
|
+
credentials = await this.anonymousLogin(credentials)
|
|
512
517
|
} else {
|
|
513
|
-
|
|
518
|
+
return this.unAuthenticatedError('no refresh token found in credentials')
|
|
514
519
|
}
|
|
515
520
|
}
|
|
516
521
|
return credentials
|
|
@@ -568,6 +573,19 @@ export class OAuth2Client implements AuthClient {
|
|
|
568
573
|
})
|
|
569
574
|
}
|
|
570
575
|
|
|
576
|
+
private async anonymousLogin(credentials: Credentials) {
|
|
577
|
+
return this.singlePromise.run('_anonymousLogin', async () => {
|
|
578
|
+
if (this.anonymousSignInFunc) {
|
|
579
|
+
const c = await this.anonymousSignInFunc(credentials)
|
|
580
|
+
credentials = c || (await this.localCredentials.getCredentials())
|
|
581
|
+
} else {
|
|
582
|
+
credentials = await this.anonymousSignIn(credentials)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return credentials
|
|
586
|
+
})
|
|
587
|
+
}
|
|
588
|
+
|
|
571
589
|
/**
|
|
572
590
|
* Check retry value.
|
|
573
591
|
* @param {number} retry
|