@cloudbase/oauth 2.19.1 → 2.19.3

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.
@@ -1,55 +1,56 @@
1
+ export declare const AUTH_API_PREFIX = "/auth";
1
2
  export declare enum ApiUrls {
2
- AUTH_SIGN_UP_URL = "/auth/v1/signup",
3
- AUTH_TOKEN_URL = "/auth/v1/token",
4
- AUTH_REVOKE_URL = "/auth/v1/revoke",
5
- WEDA_USER_URL = "/auth/v1/plugin/weda/userinfo",
6
- AUTH_RESET_PASSWORD = "/auth/v1/reset",
7
- AUTH_GET_DEVICE_CODE = "/auth/v1/device/code",
8
- CHECK_USERNAME = "/auth/v1/checkUsername",
9
- CHECK_IF_USER_EXIST = "/auth/v1/checkIfUserExist",
10
- GET_PROVIDER_TYPE = "/auth/v1/mgr/provider/providerSubType",
11
- AUTH_SIGN_IN_URL = "/auth/v1/signin",
12
- AUTH_SIGN_IN_ANONYMOUSLY_URL = "/auth/v1/signin/anonymously",
13
- AUTH_SIGN_IN_WITH_PROVIDER_URL = "/auth/v1/signin/with/provider",
14
- AUTH_SIGN_IN_WITH_WECHAT_URL = "/auth/v1/signin/wechat/noauth",
15
- AUTH_SIGN_IN_CUSTOM = "/auth/v1/signin/custom",
16
- PROVIDER_TOKEN_URL = "/auth/v1/provider/token",
17
- PROVIDER_URI_URL = "/auth/v1/provider/uri",
18
- USER_ME_URL = "/auth/v1/user/me",
19
- AUTH_SIGNOUT_URL = "/auth/v1/user/signout",
20
- USER_QUERY_URL = "/auth/v1/user/query",
21
- USER_PRIFILE_URL = "/auth/v1/user/profile",
22
- USER_BASIC_EDIT_URL = "/auth/v1/user/basic/edit",
23
- USER_TRANS_BY_PROVIDER_URL = "/auth/v1/user/trans/by/provider",
24
- PROVIDER_LIST = "/auth/v1/user/provider",
25
- PROVIDER_BIND_URL = "/auth/v1/user/provider/bind",
26
- PROVIDER_UNBIND_URL = "/auth/v1/user/provider",
27
- CHECK_PWD_URL = "/auth/v1/user/sudo",
28
- SUDO_URL = "/auth/v1/user/sudo",
29
- BIND_CONTACT_URL = "/auth/v1/user/contact",
30
- AUTH_SET_PASSWORD = "/auth/v1/user/password",
31
- AUTHORIZE_DEVICE_URL = "/auth/v1/user/device/authorize",
32
- AUTHORIZE_URL = "/auth/v1/user/authorize",
33
- AUTHORIZE_INFO_URL = "/auth/v1/user/authorize/info",
34
- AUTHORIZED_DEVICES_DELETE_URL = "/auth/v1/user/authorized/devices/",
35
- AUTH_REVOKE_ALL_URL = "/auth/v1/user/revoke/all",
36
- GET_USER_BEHAVIOR_LOG = "/auth/v1/user/security/history",
37
- VERIFICATION_URL = "/auth/v1/verification",
38
- VERIFY_URL = "/auth/v1/verification/verify",
39
- CAPTCHA_DATA_URL = "/auth/v1/captcha/data",
40
- VERIFY_CAPTCHA_DATA_URL = "/auth/v1/captcha/data/verify",
41
- GET_CAPTCHA_URL = "/auth/v1/captcha/init",
42
- GET_MINIPROGRAM_QRCODE = "/auth/v1/qrcode/generate",
43
- GET_MINIPROGRAM_QRCODE_STATUS = "/auth/v1/qrcode/get/status"
3
+ AUTH_SIGN_UP_URL = "/v1/signup",
4
+ AUTH_TOKEN_URL = "/v1/token",
5
+ AUTH_REVOKE_URL = "/v1/revoke",
6
+ WEDA_USER_URL = "/v1/plugin/weda/userinfo",
7
+ AUTH_RESET_PASSWORD = "/v1/reset",
8
+ AUTH_GET_DEVICE_CODE = "/v1/device/code",
9
+ CHECK_USERNAME = "/v1/checkUsername",
10
+ CHECK_IF_USER_EXIST = "/v1/checkIfUserExist",
11
+ GET_PROVIDER_TYPE = "/v1/mgr/provider/providerSubType",
12
+ AUTH_SIGN_IN_URL = "/v1/signin",
13
+ AUTH_SIGN_IN_ANONYMOUSLY_URL = "/v1/signin/anonymously",
14
+ AUTH_SIGN_IN_WITH_PROVIDER_URL = "/v1/signin/with/provider",
15
+ AUTH_SIGN_IN_WITH_WECHAT_URL = "/v1/signin/wechat/noauth",
16
+ AUTH_SIGN_IN_CUSTOM = "/v1/signin/custom",
17
+ PROVIDER_TOKEN_URL = "/v1/provider/token",
18
+ PROVIDER_URI_URL = "/v1/provider/uri",
19
+ USER_ME_URL = "/v1/user/me",
20
+ AUTH_SIGNOUT_URL = "/v1/user/signout",
21
+ USER_QUERY_URL = "/v1/user/query",
22
+ USER_PRIFILE_URL = "/v1/user/profile",
23
+ USER_BASIC_EDIT_URL = "/v1/user/basic/edit",
24
+ USER_TRANS_BY_PROVIDER_URL = "/v1/user/trans/by/provider",
25
+ PROVIDER_LIST = "/v1/user/provider",
26
+ PROVIDER_BIND_URL = "/v1/user/provider/bind",
27
+ PROVIDER_UNBIND_URL = "/v1/user/provider",
28
+ CHECK_PWD_URL = "/v1/user/sudo",
29
+ SUDO_URL = "/v1/user/sudo",
30
+ BIND_CONTACT_URL = "/v1/user/contact",
31
+ AUTH_SET_PASSWORD = "/v1/user/password",
32
+ AUTHORIZE_DEVICE_URL = "/v1/user/device/authorize",
33
+ AUTHORIZE_URL = "/v1/user/authorize",
34
+ AUTHORIZE_INFO_URL = "/v1/user/authorize/info",
35
+ AUTHORIZED_DEVICES_DELETE_URL = "/v1/user/authorized/devices/",
36
+ AUTH_REVOKE_ALL_URL = "/v1/user/revoke/all",
37
+ GET_USER_BEHAVIOR_LOG = "/v1/user/security/history",
38
+ VERIFICATION_URL = "/v1/verification",
39
+ VERIFY_URL = "/v1/verification/verify",
40
+ CAPTCHA_DATA_URL = "/v1/captcha/data",
41
+ VERIFY_CAPTCHA_DATA_URL = "/v1/captcha/data/verify",
42
+ GET_CAPTCHA_URL = "/v1/captcha/init",
43
+ GET_MINIPROGRAM_QRCODE = "/v1/qrcode/generate",
44
+ GET_MINIPROGRAM_QRCODE_STATUS = "/v1/qrcode/get/status"
44
45
  }
45
46
  export declare enum ApiUrlsV2 {
46
- AUTH_SIGN_IN_URL = "/auth/v2/signin/username",
47
- AUTH_TOKEN_URL = "/auth/v2/token",
48
- USER_ME_URL = "/auth/v2/user/me",
49
- VERIFY_URL = "/auth/v2/signin/verificationcode",
50
- AUTH_SIGN_IN_WITH_PROVIDER_URL = "/auth/v2/signin/with/provider",
51
- AUTH_PUBLIC_KEY = "/auth/v2/signin/publichkey",
52
- AUTH_RESET_PASSWORD = "/auth/v2/signin/password/update"
47
+ AUTH_SIGN_IN_URL = "/v2/signin/username",
48
+ AUTH_TOKEN_URL = "/v2/token",
49
+ USER_ME_URL = "/v2/user/me",
50
+ VERIFY_URL = "/v2/signin/verificationcode",
51
+ AUTH_SIGN_IN_WITH_PROVIDER_URL = "/v2/signin/with/provider",
52
+ AUTH_PUBLIC_KEY = "/v2/signin/publichkey",
53
+ AUTH_RESET_PASSWORD = "/v2/signin/password/update"
53
54
  }
54
55
  export declare enum VerificationUsages {
55
56
  REGISTER = "REGISTER",
@@ -1,57 +1,58 @@
1
+ export const AUTH_API_PREFIX = '/auth';
1
2
  export var ApiUrls;
2
3
  (function (ApiUrls) {
3
- ApiUrls["AUTH_SIGN_UP_URL"] = "/auth/v1/signup";
4
- ApiUrls["AUTH_TOKEN_URL"] = "/auth/v1/token";
5
- ApiUrls["AUTH_REVOKE_URL"] = "/auth/v1/revoke";
6
- ApiUrls["WEDA_USER_URL"] = "/auth/v1/plugin/weda/userinfo";
7
- ApiUrls["AUTH_RESET_PASSWORD"] = "/auth/v1/reset";
8
- ApiUrls["AUTH_GET_DEVICE_CODE"] = "/auth/v1/device/code";
9
- ApiUrls["CHECK_USERNAME"] = "/auth/v1/checkUsername";
10
- ApiUrls["CHECK_IF_USER_EXIST"] = "/auth/v1/checkIfUserExist";
11
- ApiUrls["GET_PROVIDER_TYPE"] = "/auth/v1/mgr/provider/providerSubType";
12
- ApiUrls["AUTH_SIGN_IN_URL"] = "/auth/v1/signin";
13
- ApiUrls["AUTH_SIGN_IN_ANONYMOUSLY_URL"] = "/auth/v1/signin/anonymously";
14
- ApiUrls["AUTH_SIGN_IN_WITH_PROVIDER_URL"] = "/auth/v1/signin/with/provider";
15
- ApiUrls["AUTH_SIGN_IN_WITH_WECHAT_URL"] = "/auth/v1/signin/wechat/noauth";
16
- ApiUrls["AUTH_SIGN_IN_CUSTOM"] = "/auth/v1/signin/custom";
17
- ApiUrls["PROVIDER_TOKEN_URL"] = "/auth/v1/provider/token";
18
- ApiUrls["PROVIDER_URI_URL"] = "/auth/v1/provider/uri";
19
- ApiUrls["USER_ME_URL"] = "/auth/v1/user/me";
20
- ApiUrls["AUTH_SIGNOUT_URL"] = "/auth/v1/user/signout";
21
- ApiUrls["USER_QUERY_URL"] = "/auth/v1/user/query";
22
- ApiUrls["USER_PRIFILE_URL"] = "/auth/v1/user/profile";
23
- ApiUrls["USER_BASIC_EDIT_URL"] = "/auth/v1/user/basic/edit";
24
- ApiUrls["USER_TRANS_BY_PROVIDER_URL"] = "/auth/v1/user/trans/by/provider";
25
- ApiUrls["PROVIDER_LIST"] = "/auth/v1/user/provider";
26
- ApiUrls["PROVIDER_BIND_URL"] = "/auth/v1/user/provider/bind";
27
- ApiUrls["PROVIDER_UNBIND_URL"] = "/auth/v1/user/provider";
28
- ApiUrls["CHECK_PWD_URL"] = "/auth/v1/user/sudo";
29
- ApiUrls["SUDO_URL"] = "/auth/v1/user/sudo";
30
- ApiUrls["BIND_CONTACT_URL"] = "/auth/v1/user/contact";
31
- ApiUrls["AUTH_SET_PASSWORD"] = "/auth/v1/user/password";
32
- ApiUrls["AUTHORIZE_DEVICE_URL"] = "/auth/v1/user/device/authorize";
33
- ApiUrls["AUTHORIZE_URL"] = "/auth/v1/user/authorize";
34
- ApiUrls["AUTHORIZE_INFO_URL"] = "/auth/v1/user/authorize/info";
35
- ApiUrls["AUTHORIZED_DEVICES_DELETE_URL"] = "/auth/v1/user/authorized/devices/";
36
- ApiUrls["AUTH_REVOKE_ALL_URL"] = "/auth/v1/user/revoke/all";
37
- ApiUrls["GET_USER_BEHAVIOR_LOG"] = "/auth/v1/user/security/history";
38
- ApiUrls["VERIFICATION_URL"] = "/auth/v1/verification";
39
- ApiUrls["VERIFY_URL"] = "/auth/v1/verification/verify";
40
- ApiUrls["CAPTCHA_DATA_URL"] = "/auth/v1/captcha/data";
41
- ApiUrls["VERIFY_CAPTCHA_DATA_URL"] = "/auth/v1/captcha/data/verify";
42
- ApiUrls["GET_CAPTCHA_URL"] = "/auth/v1/captcha/init";
43
- ApiUrls["GET_MINIPROGRAM_QRCODE"] = "/auth/v1/qrcode/generate";
44
- ApiUrls["GET_MINIPROGRAM_QRCODE_STATUS"] = "/auth/v1/qrcode/get/status";
4
+ ApiUrls["AUTH_SIGN_UP_URL"] = "/v1/signup";
5
+ ApiUrls["AUTH_TOKEN_URL"] = "/v1/token";
6
+ ApiUrls["AUTH_REVOKE_URL"] = "/v1/revoke";
7
+ ApiUrls["WEDA_USER_URL"] = "/v1/plugin/weda/userinfo";
8
+ ApiUrls["AUTH_RESET_PASSWORD"] = "/v1/reset";
9
+ ApiUrls["AUTH_GET_DEVICE_CODE"] = "/v1/device/code";
10
+ ApiUrls["CHECK_USERNAME"] = "/v1/checkUsername";
11
+ ApiUrls["CHECK_IF_USER_EXIST"] = "/v1/checkIfUserExist";
12
+ ApiUrls["GET_PROVIDER_TYPE"] = "/v1/mgr/provider/providerSubType";
13
+ ApiUrls["AUTH_SIGN_IN_URL"] = "/v1/signin";
14
+ ApiUrls["AUTH_SIGN_IN_ANONYMOUSLY_URL"] = "/v1/signin/anonymously";
15
+ ApiUrls["AUTH_SIGN_IN_WITH_PROVIDER_URL"] = "/v1/signin/with/provider";
16
+ ApiUrls["AUTH_SIGN_IN_WITH_WECHAT_URL"] = "/v1/signin/wechat/noauth";
17
+ ApiUrls["AUTH_SIGN_IN_CUSTOM"] = "/v1/signin/custom";
18
+ ApiUrls["PROVIDER_TOKEN_URL"] = "/v1/provider/token";
19
+ ApiUrls["PROVIDER_URI_URL"] = "/v1/provider/uri";
20
+ ApiUrls["USER_ME_URL"] = "/v1/user/me";
21
+ ApiUrls["AUTH_SIGNOUT_URL"] = "/v1/user/signout";
22
+ ApiUrls["USER_QUERY_URL"] = "/v1/user/query";
23
+ ApiUrls["USER_PRIFILE_URL"] = "/v1/user/profile";
24
+ ApiUrls["USER_BASIC_EDIT_URL"] = "/v1/user/basic/edit";
25
+ ApiUrls["USER_TRANS_BY_PROVIDER_URL"] = "/v1/user/trans/by/provider";
26
+ ApiUrls["PROVIDER_LIST"] = "/v1/user/provider";
27
+ ApiUrls["PROVIDER_BIND_URL"] = "/v1/user/provider/bind";
28
+ ApiUrls["PROVIDER_UNBIND_URL"] = "/v1/user/provider";
29
+ ApiUrls["CHECK_PWD_URL"] = "/v1/user/sudo";
30
+ ApiUrls["SUDO_URL"] = "/v1/user/sudo";
31
+ ApiUrls["BIND_CONTACT_URL"] = "/v1/user/contact";
32
+ ApiUrls["AUTH_SET_PASSWORD"] = "/v1/user/password";
33
+ ApiUrls["AUTHORIZE_DEVICE_URL"] = "/v1/user/device/authorize";
34
+ ApiUrls["AUTHORIZE_URL"] = "/v1/user/authorize";
35
+ ApiUrls["AUTHORIZE_INFO_URL"] = "/v1/user/authorize/info";
36
+ ApiUrls["AUTHORIZED_DEVICES_DELETE_URL"] = "/v1/user/authorized/devices/";
37
+ ApiUrls["AUTH_REVOKE_ALL_URL"] = "/v1/user/revoke/all";
38
+ ApiUrls["GET_USER_BEHAVIOR_LOG"] = "/v1/user/security/history";
39
+ ApiUrls["VERIFICATION_URL"] = "/v1/verification";
40
+ ApiUrls["VERIFY_URL"] = "/v1/verification/verify";
41
+ ApiUrls["CAPTCHA_DATA_URL"] = "/v1/captcha/data";
42
+ ApiUrls["VERIFY_CAPTCHA_DATA_URL"] = "/v1/captcha/data/verify";
43
+ ApiUrls["GET_CAPTCHA_URL"] = "/v1/captcha/init";
44
+ ApiUrls["GET_MINIPROGRAM_QRCODE"] = "/v1/qrcode/generate";
45
+ ApiUrls["GET_MINIPROGRAM_QRCODE_STATUS"] = "/v1/qrcode/get/status";
45
46
  })(ApiUrls || (ApiUrls = {}));
46
47
  export var ApiUrlsV2;
47
48
  (function (ApiUrlsV2) {
48
- ApiUrlsV2["AUTH_SIGN_IN_URL"] = "/auth/v2/signin/username";
49
- ApiUrlsV2["AUTH_TOKEN_URL"] = "/auth/v2/token";
50
- ApiUrlsV2["USER_ME_URL"] = "/auth/v2/user/me";
51
- ApiUrlsV2["VERIFY_URL"] = "/auth/v2/signin/verificationcode";
52
- ApiUrlsV2["AUTH_SIGN_IN_WITH_PROVIDER_URL"] = "/auth/v2/signin/with/provider";
53
- ApiUrlsV2["AUTH_PUBLIC_KEY"] = "/auth/v2/signin/publichkey";
54
- ApiUrlsV2["AUTH_RESET_PASSWORD"] = "/auth/v2/signin/password/update";
49
+ ApiUrlsV2["AUTH_SIGN_IN_URL"] = "/v2/signin/username";
50
+ ApiUrlsV2["AUTH_TOKEN_URL"] = "/v2/token";
51
+ ApiUrlsV2["USER_ME_URL"] = "/v2/user/me";
52
+ ApiUrlsV2["VERIFY_URL"] = "/v2/signin/verificationcode";
53
+ ApiUrlsV2["AUTH_SIGN_IN_WITH_PROVIDER_URL"] = "/v2/signin/with/provider";
54
+ ApiUrlsV2["AUTH_PUBLIC_KEY"] = "/v2/signin/publichkey";
55
+ ApiUrlsV2["AUTH_RESET_PASSWORD"] = "/v2/signin/password/update";
55
56
  })(ApiUrlsV2 || (ApiUrlsV2 = {}));
56
57
  export var VerificationUsages;
57
58
  (function (VerificationUsages) {
@@ -1,6 +1,7 @@
1
1
  import { OAuth2Client } from './oauth2client/oauth2client';
2
2
  import { AuthOptions, Auth } from './auth/apis';
3
3
  export { Auth } from './auth/apis';
4
+ export { AUTH_API_PREFIX } from './auth/consts';
4
5
  export * as authModels from './auth/models';
5
6
  export type { ProviderProfile } from './auth/models';
6
7
  export type { Credentials, OAuth2ClientOptions, ResponseError, AuthClientRequestOptions } from './oauth2client/models';
package/dist/esm/index.js CHANGED
@@ -1,19 +1,25 @@
1
1
  import { OAuth2Client } from './oauth2client/oauth2client';
2
2
  import { 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
  import * as authModels_1 from './auth/models';
5
7
  export { authModels_1 as authModels };
6
8
  export class CloudbaseOAuth {
7
9
  constructor(authOptions) {
8
- const { apiOrigin, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter } = authOptions;
10
+ const { apiOrigin, apiPath = AUTH_API_PREFIX, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError, headers, i18n } = authOptions;
9
11
  this.oauth2client = new OAuth2Client({
10
12
  apiOrigin,
13
+ apiPath,
11
14
  clientId,
12
15
  env,
13
16
  storage,
14
17
  baseRequest: baseRequest || request,
15
18
  anonymousSignInFunc,
16
19
  wxCloud,
20
+ onCredentialsError,
21
+ headers: headers || {},
22
+ i18n,
17
23
  });
18
24
  this.authApi = new Auth({
19
25
  credentialsClient: this.oauth2client,
@@ -1,5 +1,7 @@
1
1
  import { SimpleStorage } from './interface';
2
2
  import { ErrorType } from './consts';
3
+ import { AuthOptions } from '../auth/apis';
4
+ import { ICloudbaseConfig } from '@cloudbase/types';
3
5
  export interface Credentials {
4
6
  token_type?: string | null;
5
7
  access_token?: string | null;
@@ -38,6 +40,7 @@ export interface AuthClientRequestOptions extends RequestOptions {
38
40
  export interface OAuth2ClientOptions {
39
41
  devMode?: boolean;
40
42
  apiOrigin: string;
43
+ apiPath?: string;
41
44
  clientId: string;
42
45
  env: string;
43
46
  retry?: number;
@@ -51,4 +54,6 @@ export interface OAuth2ClientOptions {
51
54
  };
52
55
  anonymousSignInFunc?: (Credentials: any) => Promise<Credentials | void>;
53
56
  wxCloud?: any;
57
+ onCredentialsError?: AuthOptions['onCredentialsError'];
58
+ i18n?: ICloudbaseConfig['i18n'];
54
59
  }
@@ -29,7 +29,9 @@ export declare class OAuth2Client implements AuthClient {
29
29
  private static maxRetry;
30
30
  private static retryInterval;
31
31
  private apiOrigin;
32
+ private apiPath;
32
33
  private clientId;
34
+ private i18n;
33
35
  private retry;
34
36
  private clientSecret?;
35
37
  private baseRequest;
@@ -43,6 +45,7 @@ export declare class OAuth2Client implements AuthClient {
43
45
  private anonymousSignInFunc;
44
46
  private wxCloud;
45
47
  private basicAuth;
48
+ private onCredentialsError;
46
49
  constructor(options: OAuth2ClientOptions);
47
50
  setCredentials(credentials?: Credentials): Promise<void>;
48
51
  getAccessToken(): Promise<string>;
@@ -1,10 +1,11 @@
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
  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
7
  import { isMatch } from '../utils/cloudbase-adapter-wx_mp';
8
+ import { langEvent } from '@cloudbase/utilities';
8
9
  const RequestIdHeaderName = 'x-request-id';
9
10
  const DeviceIdHeaderName = 'x-device-id';
10
11
  const DeviceIdSectionName = 'device_id';
@@ -181,7 +182,9 @@ class OAuth2Client {
181
182
  options.clientId = options.env;
182
183
  }
183
184
  this.apiOrigin = options.apiOrigin;
185
+ this.apiPath = options.apiPath || AUTH_API_PREFIX;
184
186
  this.clientId = options.clientId;
187
+ this.i18n = options.i18n;
185
188
  this.singlePromise = new SinglePromise({ clientId: this.clientId });
186
189
  this.retry = this.formatRetry(options.retry, OAuth2Client.defaultRetry);
187
190
  if (options.baseRequest) {
@@ -213,6 +216,10 @@ class OAuth2Client {
213
216
  }
214
217
  this.refreshTokenFunc = options.refreshTokenFunc || this.defaultRefreshTokenFunc;
215
218
  this.anonymousSignInFunc = options.anonymousSignInFunc;
219
+ this.onCredentialsError = options.onCredentialsError;
220
+ langEvent.bus.on(langEvent.LANG_CHANGE_EVENT, (params) => {
221
+ this.i18n = params.data?.i18n || this.i18n;
222
+ });
216
223
  }
217
224
  setCredentials(credentials) {
218
225
  return this.localCredentials.setCredentials(credentials);
@@ -230,7 +237,7 @@ class OAuth2Client {
230
237
  options = {};
231
238
  }
232
239
  const retry = this.formatRetry(options.retry, this.retry);
233
- options.headers = options.headers || {};
240
+ options.headers = { ...options.headers, [this.i18n?.LANG_HEADER_KEY]: this.i18n?.lang };
234
241
  if (this.headers) {
235
242
  options.headers = {
236
243
  ...this.headers,
@@ -268,7 +275,7 @@ class OAuth2Client {
268
275
  }
269
276
  }
270
277
  if (url.startsWith('/')) {
271
- url = this.apiOrigin + url;
278
+ url = `${this.apiOrigin}${this.apiPath}${url}`;
272
279
  }
273
280
  let response = null;
274
281
  const maxRequestTimes = retry + 1;
@@ -342,7 +349,9 @@ class OAuth2Client {
342
349
  async getCredentials() {
343
350
  let credentials = await this.localCredentials.getCredentials();
344
351
  if (!credentials) {
345
- return this.unAuthenticatedError('credentials not found');
352
+ const msg = 'credentials not found';
353
+ this.onCredentialsError?.({ msg });
354
+ return this.unAuthenticatedError(msg);
346
355
  }
347
356
  if (isCredentialsExpired(credentials)) {
348
357
  if (credentials.refresh_token) {
@@ -354,6 +363,7 @@ class OAuth2Client {
354
363
  credentials = await this.anonymousLogin(credentials);
355
364
  }
356
365
  else {
366
+ this.onCredentialsError?.({ msg: error.error_description });
357
367
  return Promise.reject(error);
358
368
  }
359
369
  }
@@ -362,7 +372,9 @@ class OAuth2Client {
362
372
  credentials = await this.anonymousLogin(credentials);
363
373
  }
364
374
  else {
365
- return this.unAuthenticatedError('no refresh token found in credentials');
375
+ const msg = 'no refresh token found in credentials';
376
+ this.onCredentialsError?.({ msg });
377
+ return this.unAuthenticatedError(msg);
366
378
  }
367
379
  }
368
380
  return credentials;
@@ -377,21 +389,27 @@ class OAuth2Client {
377
389
  async getScope() {
378
390
  const credentials = await this.localCredentials.getCredentials();
379
391
  if (!credentials) {
380
- return this.unAuthenticatedError('credentials not found');
392
+ const msg = 'credentials not found';
393
+ this.onCredentialsError?.({ msg });
394
+ return this.unAuthenticatedError(msg);
381
395
  }
382
396
  return credentials.scope;
383
397
  }
384
398
  async getGroups() {
385
399
  const credentials = await this.localCredentials.getCredentials();
386
400
  if (!credentials) {
387
- return this.unAuthenticatedError('credentials not found');
401
+ const msg = 'credentials not found';
402
+ this.onCredentialsError?.({ msg });
403
+ return this.unAuthenticatedError(msg);
388
404
  }
389
405
  return credentials.groups;
390
406
  }
391
407
  async refreshToken(credentials) {
392
408
  return this.singlePromise.run('_refreshToken', async () => {
393
409
  if (!credentials || !credentials.refresh_token) {
394
- return this.unAuthenticatedError('no refresh token found in credentials');
410
+ const msg = 'no refresh token found in credentials';
411
+ this.onCredentialsError?.({ msg });
412
+ return this.unAuthenticatedError(msg);
395
413
  }
396
414
  try {
397
415
  const newCredentials = await this.refreshTokenFunc(credentials.refresh_token, credentials);
@@ -401,8 +419,11 @@ class OAuth2Client {
401
419
  catch (error) {
402
420
  if (error.error === ErrorType.INVALID_GRANT) {
403
421
  await this.localCredentials.setCredentials(null);
404
- return this.unAuthenticatedError(error.error_description);
422
+ const msg = error.error_description;
423
+ this.onCredentialsError?.({ msg });
424
+ return this.unAuthenticatedError(msg);
405
425
  }
426
+ this.onCredentialsError?.({ msg: error.error_description });
406
427
  return Promise.reject(error);
407
428
  }
408
429
  });
@@ -470,7 +491,9 @@ class OAuth2Client {
470
491
  }
471
492
  async defaultRefreshTokenFunc(refreshToken, credentials) {
472
493
  if (refreshToken === undefined || refreshToken === '') {
473
- return this.unAuthenticatedError('refresh token not found');
494
+ const msg = 'refresh token not found';
495
+ this.onCredentialsError?.({ msg });
496
+ return this.unAuthenticatedError(msg);
474
497
  }
475
498
  let url = ApiUrls.AUTH_TOKEN_URL;
476
499
  if (credentials?.version === 'v2') {