@cloudbase/oauth 2.19.2 → 2.19.4
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 +6 -0
- package/dist/cjs/auth/apis.js +5 -1
- package/dist/cjs/auth/consts.d.ts +50 -49
- package/dist/cjs/auth/consts.js +52 -51
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +9 -3
- package/dist/cjs/oauth2client/models.d.ts +3 -0
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +2 -0
- package/dist/cjs/oauth2client/oauth2client.js +29 -19
- package/dist/esm/auth/apis.d.ts +6 -0
- package/dist/esm/auth/apis.js +4 -0
- package/dist/esm/auth/consts.d.ts +50 -49
- package/dist/esm/auth/consts.js +50 -49
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/oauth2client/models.d.ts +3 -0
- package/dist/esm/oauth2client/oauth2client.d.ts +2 -0
- package/dist/esm/oauth2client/oauth2client.js +9 -3
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -3
- package/src/auth/apis.ts +8 -0
- package/src/auth/consts.ts +51 -49
- package/src/index.ts +6 -1
- package/src/oauth2client/models.ts +3 -0
- package/src/oauth2client/oauth2client.ts +13 -3
package/src/auth/consts.ts
CHANGED
|
@@ -1,62 +1,64 @@
|
|
|
1
|
+
export const AUTH_API_PREFIX = '/auth'
|
|
2
|
+
|
|
1
3
|
export enum ApiUrls {
|
|
2
|
-
AUTH_SIGN_UP_URL = '/
|
|
3
|
-
AUTH_TOKEN_URL = '/
|
|
4
|
-
AUTH_REVOKE_URL = '/
|
|
5
|
-
WEDA_USER_URL = '/
|
|
6
|
-
AUTH_RESET_PASSWORD = '/
|
|
7
|
-
AUTH_GET_DEVICE_CODE = '/
|
|
8
|
-
CHECK_USERNAME = '/
|
|
9
|
-
CHECK_IF_USER_EXIST = '/
|
|
10
|
-
GET_PROVIDER_TYPE = '/
|
|
4
|
+
AUTH_SIGN_UP_URL = '/v1/signup',
|
|
5
|
+
AUTH_TOKEN_URL = '/v1/token',
|
|
6
|
+
AUTH_REVOKE_URL = '/v1/revoke',
|
|
7
|
+
WEDA_USER_URL = '/v1/plugin/weda/userinfo',
|
|
8
|
+
AUTH_RESET_PASSWORD = '/v1/reset',
|
|
9
|
+
AUTH_GET_DEVICE_CODE = '/v1/device/code',
|
|
10
|
+
CHECK_USERNAME = '/v1/checkUsername',
|
|
11
|
+
CHECK_IF_USER_EXIST = '/v1/checkIfUserExist',
|
|
12
|
+
GET_PROVIDER_TYPE = '/v1/mgr/provider/providerSubType',
|
|
11
13
|
|
|
12
|
-
AUTH_SIGN_IN_URL = '/
|
|
13
|
-
AUTH_SIGN_IN_ANONYMOUSLY_URL = '/
|
|
14
|
-
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/
|
|
15
|
-
AUTH_SIGN_IN_WITH_WECHAT_URL = '/
|
|
16
|
-
AUTH_SIGN_IN_CUSTOM = '/
|
|
14
|
+
AUTH_SIGN_IN_URL = '/v1/signin',
|
|
15
|
+
AUTH_SIGN_IN_ANONYMOUSLY_URL = '/v1/signin/anonymously',
|
|
16
|
+
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/v1/signin/with/provider',
|
|
17
|
+
AUTH_SIGN_IN_WITH_WECHAT_URL = '/v1/signin/wechat/noauth',
|
|
18
|
+
AUTH_SIGN_IN_CUSTOM = '/v1/signin/custom',
|
|
17
19
|
|
|
18
|
-
PROVIDER_TOKEN_URL = '/
|
|
19
|
-
PROVIDER_URI_URL = '/
|
|
20
|
+
PROVIDER_TOKEN_URL = '/v1/provider/token',
|
|
21
|
+
PROVIDER_URI_URL = '/v1/provider/uri',
|
|
20
22
|
|
|
21
|
-
USER_ME_URL = '/
|
|
22
|
-
AUTH_SIGNOUT_URL = '/
|
|
23
|
-
USER_QUERY_URL = '/
|
|
24
|
-
USER_PRIFILE_URL = '/
|
|
25
|
-
USER_BASIC_EDIT_URL = '/
|
|
26
|
-
USER_TRANS_BY_PROVIDER_URL = '/
|
|
27
|
-
PROVIDER_LIST = '/
|
|
28
|
-
PROVIDER_BIND_URL = '/
|
|
29
|
-
PROVIDER_UNBIND_URL = '/
|
|
30
|
-
CHECK_PWD_URL = '/
|
|
31
|
-
SUDO_URL = '/
|
|
32
|
-
BIND_CONTACT_URL = '/
|
|
33
|
-
AUTH_SET_PASSWORD = '/
|
|
34
|
-
AUTHORIZE_DEVICE_URL = '/
|
|
35
|
-
AUTHORIZE_URL = '/
|
|
36
|
-
AUTHORIZE_INFO_URL = '/
|
|
37
|
-
AUTHORIZED_DEVICES_DELETE_URL = '/
|
|
38
|
-
AUTH_REVOKE_ALL_URL = '/
|
|
39
|
-
GET_USER_BEHAVIOR_LOG = '/
|
|
23
|
+
USER_ME_URL = '/v1/user/me',
|
|
24
|
+
AUTH_SIGNOUT_URL = '/v1/user/signout',
|
|
25
|
+
USER_QUERY_URL = '/v1/user/query',
|
|
26
|
+
USER_PRIFILE_URL = '/v1/user/profile',
|
|
27
|
+
USER_BASIC_EDIT_URL = '/v1/user/basic/edit',
|
|
28
|
+
USER_TRANS_BY_PROVIDER_URL = '/v1/user/trans/by/provider',
|
|
29
|
+
PROVIDER_LIST = '/v1/user/provider',
|
|
30
|
+
PROVIDER_BIND_URL = '/v1/user/provider/bind',
|
|
31
|
+
PROVIDER_UNBIND_URL = '/v1/user/provider',
|
|
32
|
+
CHECK_PWD_URL = '/v1/user/sudo',
|
|
33
|
+
SUDO_URL = '/v1/user/sudo',
|
|
34
|
+
BIND_CONTACT_URL = '/v1/user/contact',
|
|
35
|
+
AUTH_SET_PASSWORD = '/v1/user/password',
|
|
36
|
+
AUTHORIZE_DEVICE_URL = '/v1/user/device/authorize',
|
|
37
|
+
AUTHORIZE_URL = '/v1/user/authorize',
|
|
38
|
+
AUTHORIZE_INFO_URL = '/v1/user/authorize/info',
|
|
39
|
+
AUTHORIZED_DEVICES_DELETE_URL = '/v1/user/authorized/devices/',
|
|
40
|
+
AUTH_REVOKE_ALL_URL = '/v1/user/revoke/all',
|
|
41
|
+
GET_USER_BEHAVIOR_LOG = '/v1/user/security/history',
|
|
40
42
|
|
|
41
|
-
VERIFICATION_URL = '/
|
|
42
|
-
VERIFY_URL = '/
|
|
43
|
+
VERIFICATION_URL = '/v1/verification',
|
|
44
|
+
VERIFY_URL = '/v1/verification/verify',
|
|
43
45
|
|
|
44
|
-
CAPTCHA_DATA_URL = '/
|
|
45
|
-
VERIFY_CAPTCHA_DATA_URL = '/
|
|
46
|
-
GET_CAPTCHA_URL = '/
|
|
46
|
+
CAPTCHA_DATA_URL = '/v1/captcha/data',
|
|
47
|
+
VERIFY_CAPTCHA_DATA_URL = '/v1/captcha/data/verify',
|
|
48
|
+
GET_CAPTCHA_URL = '/v1/captcha/init',
|
|
47
49
|
|
|
48
|
-
GET_MINIPROGRAM_QRCODE = '/
|
|
49
|
-
GET_MINIPROGRAM_QRCODE_STATUS = '/
|
|
50
|
+
GET_MINIPROGRAM_QRCODE = '/v1/qrcode/generate',
|
|
51
|
+
GET_MINIPROGRAM_QRCODE_STATUS = '/v1/qrcode/get/status',
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
export enum ApiUrlsV2 {
|
|
53
|
-
AUTH_SIGN_IN_URL = '/
|
|
54
|
-
AUTH_TOKEN_URL = '/
|
|
55
|
-
USER_ME_URL = '/
|
|
56
|
-
VERIFY_URL = '/
|
|
57
|
-
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/
|
|
58
|
-
AUTH_PUBLIC_KEY = '/
|
|
59
|
-
AUTH_RESET_PASSWORD = '/
|
|
55
|
+
AUTH_SIGN_IN_URL = '/v2/signin/username',
|
|
56
|
+
AUTH_TOKEN_URL = '/v2/token',
|
|
57
|
+
USER_ME_URL = '/v2/user/me',
|
|
58
|
+
VERIFY_URL = '/v2/signin/verificationcode',
|
|
59
|
+
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/v2/signin/with/provider',
|
|
60
|
+
AUTH_PUBLIC_KEY = '/v2/signin/publichkey',
|
|
61
|
+
AUTH_RESET_PASSWORD = '/v2/signin/password/update'
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export enum VerificationUsages {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OAuth2Client } from './oauth2client/oauth2client'
|
|
2
2
|
import { AuthOptions, Auth } from './auth/apis'
|
|
3
|
+
import { AUTH_API_PREFIX } from './auth/consts'
|
|
3
4
|
export { Auth } from './auth/apis'
|
|
5
|
+
export { AUTH_API_PREFIX } from './auth/consts'
|
|
4
6
|
export * as authModels from './auth/models'
|
|
5
7
|
export type { ProviderProfile } from './auth/models'
|
|
6
8
|
export type { Credentials, OAuth2ClientOptions, ResponseError, AuthClientRequestOptions } from './oauth2client/models'
|
|
@@ -11,9 +13,10 @@ export class CloudbaseOAuth {
|
|
|
11
13
|
public authApi: Auth
|
|
12
14
|
|
|
13
15
|
constructor(authOptions: AuthOptions) {
|
|
14
|
-
const { apiOrigin, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError } = authOptions
|
|
16
|
+
const { apiOrigin, apiPath = AUTH_API_PREFIX, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError, headers, i18n } = authOptions
|
|
15
17
|
this.oauth2client = new OAuth2Client({
|
|
16
18
|
apiOrigin,
|
|
19
|
+
apiPath,
|
|
17
20
|
clientId,
|
|
18
21
|
env,
|
|
19
22
|
storage,
|
|
@@ -21,6 +24,8 @@ export class CloudbaseOAuth {
|
|
|
21
24
|
anonymousSignInFunc,
|
|
22
25
|
wxCloud,
|
|
23
26
|
onCredentialsError,
|
|
27
|
+
headers: headers || {},
|
|
28
|
+
i18n,
|
|
24
29
|
})
|
|
25
30
|
|
|
26
31
|
this.authApi = new Auth({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SimpleStorage } from './interface'
|
|
2
2
|
import { ErrorType } from './consts'
|
|
3
3
|
import { AuthOptions } from '../auth/apis'
|
|
4
|
+
import { ICloudbaseConfig } from '@cloudbase/types'
|
|
4
5
|
|
|
5
6
|
/** Credentials **/
|
|
6
7
|
export interface Credentials {
|
|
@@ -52,6 +53,7 @@ export interface AuthClientRequestOptions extends RequestOptions {
|
|
|
52
53
|
export interface OAuth2ClientOptions {
|
|
53
54
|
devMode?: boolean;
|
|
54
55
|
apiOrigin: string;
|
|
56
|
+
apiPath?: string;
|
|
55
57
|
clientId: string;
|
|
56
58
|
env: string;
|
|
57
59
|
// default value is 1,min value is 0, max value is 5
|
|
@@ -68,4 +70,5 @@ export interface OAuth2ClientOptions {
|
|
|
68
70
|
anonymousSignInFunc?: (Credentials) => Promise<Credentials | void>
|
|
69
71
|
wxCloud?: any;
|
|
70
72
|
onCredentialsError?: AuthOptions['onCredentialsError']
|
|
73
|
+
i18n?: ICloudbaseConfig['i18n']
|
|
71
74
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorType } from './consts'
|
|
2
|
-
import { ApiUrls, ApiUrlsV2 } from '../auth/consts'
|
|
2
|
+
import { ApiUrls, ApiUrlsV2, AUTH_API_PREFIX } from '../auth/consts'
|
|
3
3
|
|
|
4
4
|
import { AuthClient, SimpleStorage } from './interface'
|
|
5
5
|
|
|
@@ -19,6 +19,8 @@ import { SinglePromise } from '../utils/function/single-promise'
|
|
|
19
19
|
import { weBtoa } from '../utils/base64'
|
|
20
20
|
import { isMatch } from '../utils/cloudbase-adapter-wx_mp'
|
|
21
21
|
import { AuthOptions } from '../auth/apis'
|
|
22
|
+
import { ICloudbaseConfig } from '@cloudbase/types'
|
|
23
|
+
import { langEvent } from '@cloudbase/utilities'
|
|
22
24
|
|
|
23
25
|
const RequestIdHeaderName = 'x-request-id'
|
|
24
26
|
const DeviceIdHeaderName = 'x-device-id'
|
|
@@ -293,7 +295,9 @@ export class OAuth2Client implements AuthClient {
|
|
|
293
295
|
private static retryInterval = 1000
|
|
294
296
|
|
|
295
297
|
private apiOrigin: string
|
|
298
|
+
private apiPath: string
|
|
296
299
|
private clientId: string
|
|
300
|
+
private i18n: ICloudbaseConfig['i18n']
|
|
297
301
|
private retry: number
|
|
298
302
|
private clientSecret?: string
|
|
299
303
|
private baseRequest: <T>(url: string, options?: RequestOptions) => Promise<T>
|
|
@@ -323,7 +327,9 @@ export class OAuth2Client implements AuthClient {
|
|
|
323
327
|
}
|
|
324
328
|
|
|
325
329
|
this.apiOrigin = options.apiOrigin
|
|
330
|
+
this.apiPath = options.apiPath || AUTH_API_PREFIX
|
|
326
331
|
this.clientId = options.clientId
|
|
332
|
+
this.i18n = options.i18n
|
|
327
333
|
this.singlePromise = new SinglePromise({ clientId: this.clientId })
|
|
328
334
|
this.retry = this.formatRetry(options.retry, OAuth2Client.defaultRetry)
|
|
329
335
|
if (options.baseRequest) {
|
|
@@ -357,6 +363,10 @@ export class OAuth2Client implements AuthClient {
|
|
|
357
363
|
this.refreshTokenFunc = options.refreshTokenFunc || this.defaultRefreshTokenFunc
|
|
358
364
|
this.anonymousSignInFunc = options.anonymousSignInFunc
|
|
359
365
|
this.onCredentialsError = options.onCredentialsError
|
|
366
|
+
|
|
367
|
+
langEvent.bus.on(langEvent.LANG_CHANGE_EVENT, (params) => {
|
|
368
|
+
this.i18n = params.data?.i18n || this.i18n
|
|
369
|
+
})
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
/**
|
|
@@ -390,7 +400,7 @@ export class OAuth2Client implements AuthClient {
|
|
|
390
400
|
options = {}
|
|
391
401
|
}
|
|
392
402
|
const retry: number = this.formatRetry(options.retry, this.retry)
|
|
393
|
-
options.headers = options.headers
|
|
403
|
+
options.headers = { ...options.headers, [this.i18n?.LANG_HEADER_KEY]: this.i18n?.lang }
|
|
394
404
|
if (this.headers) {
|
|
395
405
|
options.headers = {
|
|
396
406
|
...this.headers,
|
|
@@ -426,7 +436,7 @@ export class OAuth2Client implements AuthClient {
|
|
|
426
436
|
}
|
|
427
437
|
}
|
|
428
438
|
if (url.startsWith('/')) {
|
|
429
|
-
url = this.apiOrigin
|
|
439
|
+
url = `${this.apiOrigin}${this.apiPath}${url}`
|
|
430
440
|
}
|
|
431
441
|
let response: T | null = null
|
|
432
442
|
const maxRequestTimes: number = retry + 1
|