@cloudbase/oauth 0.1.1-alpha.8 → 0.1.1-alpha.9

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.
Files changed (54) hide show
  1. package/dist/app/index.d.ts +3 -1
  2. package/dist/app/index.js +9 -3
  3. package/dist/app/internal.js +0 -1
  4. package/dist/app/openuri.d.ts +1 -0
  5. package/dist/app/openuri.js +10 -8
  6. package/dist/app/request.js +0 -1
  7. package/dist/app/storage.js +0 -1
  8. package/dist/auth/consts.d.ts +3 -0
  9. package/dist/auth/consts.js +3 -1
  10. package/dist/auth/index.d.ts +26 -6
  11. package/dist/auth/index.js +64 -43
  12. package/dist/auth/models.js +0 -1
  13. package/dist/captcha/index.d.ts +10 -9
  14. package/dist/captcha/index.js +69 -50
  15. package/dist/function/index.js +0 -1
  16. package/dist/index.js +0 -1
  17. package/dist/oauthclient/consts.js +0 -1
  18. package/dist/oauthclient/index.js +0 -1
  19. package/dist/oauthclient/interface.js +0 -1
  20. package/dist/oauthclient/models.js +0 -1
  21. package/dist/oauthclient/oauthclient.js +0 -1
  22. package/dist/package.json +1 -1
  23. package/dist/utils/base64.js +0 -1
  24. package/dist/utils/mp.d.ts +2 -0
  25. package/dist/utils/mp.js +57 -0
  26. package/dist/utils/promise.js +0 -1
  27. package/dist/utils/uuid.js +0 -1
  28. package/package.json +1 -1
  29. package/src/app/index.ts +12 -3
  30. package/src/app/openuri.ts +14 -7
  31. package/src/auth/consts.ts +69 -66
  32. package/src/auth/index.ts +156 -209
  33. package/src/captcha/index.ts +165 -138
  34. package/src/utils/mp.ts +55 -0
  35. package/tsconfig.json +5 -18
  36. package/dist/app/index.js.map +0 -1
  37. package/dist/app/internal.js.map +0 -1
  38. package/dist/app/openuri.js.map +0 -1
  39. package/dist/app/request.js.map +0 -1
  40. package/dist/app/storage.js.map +0 -1
  41. package/dist/auth/consts.js.map +0 -1
  42. package/dist/auth/index.js.map +0 -1
  43. package/dist/auth/models.js.map +0 -1
  44. package/dist/captcha/index.js.map +0 -1
  45. package/dist/function/index.js.map +0 -1
  46. package/dist/index.js.map +0 -1
  47. package/dist/oauthclient/consts.js.map +0 -1
  48. package/dist/oauthclient/index.js.map +0 -1
  49. package/dist/oauthclient/interface.js.map +0 -1
  50. package/dist/oauthclient/models.js.map +0 -1
  51. package/dist/oauthclient/oauthclient.js.map +0 -1
  52. package/dist/utils/base64.js.map +0 -1
  53. package/dist/utils/promise.js.map +0 -1
  54. package/dist/utils/uuid.js.map +0 -1
@@ -11,7 +11,9 @@ export interface Options {
11
11
  request?: requestFn;
12
12
  baseRequest?: requestFn;
13
13
  storage?: storage;
14
- openURIWithCallback?: openURIWithCallback;
14
+ captchaOptions?: {
15
+ openURIWithCallback?: openURIWithCallback;
16
+ };
15
17
  }
16
18
  export declare function initializeApp(options: Options): App;
17
19
  export interface App {
package/dist/app/index.js CHANGED
@@ -27,10 +27,17 @@ class AppImpl {
27
27
  if (!options.storage) {
28
28
  options.storage = new storage_1.DefaultStorage({ env: storageEnv });
29
29
  }
30
- if (!options.openURIWithCallback) {
31
- options.openURIWithCallback = openuri_1.defaultOpenURIWithCallback;
30
+ if (!options.captchaOptions) {
31
+ options.captchaOptions = {};
32
+ }
33
+ if (!options.captchaOptions.openURIWithCallback) {
34
+ // 兼容之前的传参方式,options.openURIWithCallback
35
+ options.captchaOptions.openURIWithCallback = options.openURIWithCallback || openuri_1.defaultOpenURIWithCallback;
32
36
  }
33
37
  let baseRequest = options.baseRequest || options.request || request_1.defaultRequest;
38
+ if (!baseRequest) {
39
+ baseRequest = request_1.defaultRequest;
40
+ }
34
41
  const apiOrigin = options.apiOrigin;
35
42
  options.request = async (url, options) => {
36
43
  if (url.startsWith('/')) {
@@ -48,4 +55,3 @@ class AppImpl {
48
55
  }
49
56
  }
50
57
  exports.AppImpl = AppImpl;
51
- //# sourceMappingURL=index.js.map
@@ -22,4 +22,3 @@ function _getComponent(app, name, creator) {
22
22
  return component;
23
23
  }
24
24
  exports._getComponent = _getComponent;
25
- //# sourceMappingURL=internal.js.map
@@ -4,6 +4,7 @@ export declare type OpenURIWithCallback = (url: string, opts?: OpenURIOptions) =
4
4
  export interface OpenURIOptions {
5
5
  width: string;
6
6
  height: string;
7
+ request?: any;
7
8
  }
8
9
  /**
9
10
  * default use iframe to open url can return callback
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultOpenURIWithCallback = void 0;
4
+ const consts_1 = require("../auth/consts");
4
5
  /**
5
6
  * default use iframe to open url can return callback
6
7
  * for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/
@@ -15,15 +16,17 @@ exports.defaultOpenURIWithCallback = void 0;
15
16
  */
16
17
  const defaultOpenURIWithCallback = (url, opts) => {
17
18
  let iframeTag = '__iframe';
19
+ const { width = '355px', height = '355px' } = opts || {};
20
+ const matched = url.match(/^(data:.*)$/);
21
+ if (matched) {
22
+ return Promise.reject({
23
+ error: consts_1.ErrorType.UNIMPLEMENTED,
24
+ error_description: `need to impl captcha data`,
25
+ });
26
+ }
18
27
  if (window.location.search.indexOf(iframeTag) > 0) {
19
28
  document.body.style.display = 'none';
20
29
  }
21
- if (!opts) {
22
- opts = {
23
- width: '355px',
24
- height: '355px',
25
- };
26
- }
27
30
  if (document.getElementById('_iframe_panel_wrap') === null) {
28
31
  var elementDiv = document.createElement('div');
29
32
  elementDiv.style.cssText =
@@ -50,7 +53,7 @@ const defaultOpenURIWithCallback = (url, opts) => {
50
53
  }
51
54
  iframe.setAttribute('src', url);
52
55
  iframe.setAttribute('id', '_iframe_panel_wrap_iframe');
53
- iframe.style.cssText = `min-width:${opts.width};display:block;height:${opts.height};margin:0 auto;background-color: rgb(255, 255, 255);border: none;`;
56
+ iframe.style.cssText = `min-width:${width};display:block;height:${height};margin:0 auto;background-color: rgb(255, 255, 255);border: none;`;
54
57
  target.appendChild(iframe);
55
58
  target.style.display = 'block';
56
59
  let callBack = new Callback();
@@ -108,4 +111,3 @@ const defaultOpenURIWithCallback = (url, opts) => {
108
111
  exports.defaultOpenURIWithCallback = defaultOpenURIWithCallback;
109
112
  class Callback {
110
113
  }
111
- //# sourceMappingURL=openuri.js.map
@@ -55,4 +55,3 @@ const defaultRequest = async (url, options) => {
55
55
  }
56
56
  };
57
57
  exports.defaultRequest = defaultRequest;
58
- //# sourceMappingURL=request.js.map
@@ -32,4 +32,3 @@ class DefaultStorage {
32
32
  }
33
33
  }
34
34
  exports.DefaultStorage = DefaultStorage;
35
- //# sourceMappingURL=storage.js.map
@@ -16,6 +16,9 @@ export declare enum ApiUrls {
16
16
  USER_TRANS_BY_PROVIDER_URL = "/auth/v1/user/trans/by/provider",
17
17
  VERIFICATION_URL = "/auth/v1/verification",
18
18
  VERIFY_URL = "/auth/v1/verification/verify",
19
+ CAPTCHA_DATA_URL = "/auth/v1/captcha/data",
20
+ VERIFY_CAPTCHA_DATA_URL = "/auth/v1/captcha/data/verify",
21
+ GET_CAPTCHA_URL = "/auth/v1/captcha/init",
19
22
  PROVIDER_LIST_URL = "/auth/v1/user/provider",
20
23
  PROVIDER_UNBIND_URL = "/auth/v1/user/provider",
21
24
  SUDO_URL = "/auth/v1/user/sudo",
@@ -20,6 +20,9 @@ var ApiUrls;
20
20
  ApiUrls["USER_TRANS_BY_PROVIDER_URL"] = "/auth/v1/user/trans/by/provider";
21
21
  ApiUrls["VERIFICATION_URL"] = "/auth/v1/verification";
22
22
  ApiUrls["VERIFY_URL"] = "/auth/v1/verification/verify";
23
+ ApiUrls["CAPTCHA_DATA_URL"] = "/auth/v1/captcha/data";
24
+ ApiUrls["VERIFY_CAPTCHA_DATA_URL"] = "/auth/v1/captcha/data/verify";
25
+ ApiUrls["GET_CAPTCHA_URL"] = "/auth/v1/captcha/init";
23
26
  ApiUrls["PROVIDER_LIST_URL"] = "/auth/v1/user/provider";
24
27
  ApiUrls["PROVIDER_UNBIND_URL"] = "/auth/v1/user/provider";
25
28
  ApiUrls["SUDO_URL"] = "/auth/v1/user/sudo";
@@ -78,4 +81,3 @@ var DeviceAuthorizeState;
78
81
  // 用户拒绝授权
79
82
  DeviceAuthorizeState["ACCESS_DENIED"] = "ACCESS_DENIED";
80
83
  })(DeviceAuthorizeState = exports.DeviceAuthorizeState || (exports.DeviceAuthorizeState = {}));
81
- //# sourceMappingURL=consts.js.map
@@ -1,9 +1,9 @@
1
- import { UserProfile, SignInRequest, SignUpRequest, VerifyRequest, VerifyResponse, GenProviderRedirectUriRequest, GenProviderRedirectUriResponse, GrantProviderTokenRequest, GrantProviderTokenResponse, PatchProviderTokenRequest, PatchProviderTokenResponse, SignInWithProviderRequest, BindWithProviderRequest, TransByProviderRequest, GrantTokenRequest, UnbindProviderRequest, CheckPasswordRequest, SetPasswordRequest, ChangeBoundProviderRequest, ChangeBoundProviderResponse, QueryUserProfileRequest, UpdatePasswordRequest, SudoRequest, SudoResponse, QueryUserProfileResponse, EditContactRequest, CheckIfUserExistResponse, CheckIfUserExistRequest, SendVerificationCodeRequest, SendVerificationCodeResponse, ResetPasswordRequest, AuthorizeRequest, AuthorizeResponse, AuthorizeInfoRequest, AuthorizeInfoResponse, RevokeDeviceRequest, WithSudoRequest, AuthorizeDeviceRequest, DeviceAuthorizeRequest, DeviceAuthorizeResponse, ProvidersResponse, SignoutRequest, SignoutReponse, ProviderSubType } from "./models";
2
- import { Credentials, AuthClient } from "../oauthclient";
3
- import { Captcha } from "../captcha";
4
- import { App, RequestFn as appRequestFn } from "../app";
5
- export { ErrorType, VerificationUsages, DeviceAuthorizeState } from "./consts";
6
- export { ResponseError } from "../oauthclient";
1
+ import { UserProfile, SignInRequest, SignUpRequest, VerifyRequest, VerifyResponse, GenProviderRedirectUriRequest, GenProviderRedirectUriResponse, GrantProviderTokenRequest, GrantProviderTokenResponse, PatchProviderTokenRequest, PatchProviderTokenResponse, SignInWithProviderRequest, BindWithProviderRequest, TransByProviderRequest, GrantTokenRequest, UnbindProviderRequest, CheckPasswordRequest, SetPasswordRequest, ChangeBoundProviderRequest, ChangeBoundProviderResponse, QueryUserProfileRequest, UpdatePasswordRequest, SudoRequest, SudoResponse, QueryUserProfileResponse, EditContactRequest, CheckIfUserExistResponse, CheckIfUserExistRequest, SendVerificationCodeRequest, SendVerificationCodeResponse, ResetPasswordRequest, AuthorizeRequest, AuthorizeResponse, AuthorizeInfoRequest, AuthorizeInfoResponse, RevokeDeviceRequest, WithSudoRequest, AuthorizeDeviceRequest, DeviceAuthorizeRequest, DeviceAuthorizeResponse, ProvidersResponse, SignoutRequest, SignoutReponse, ProviderSubType } from './models';
2
+ import { Credentials, AuthClient } from '../oauthclient';
3
+ import { Captcha } from '../captcha';
4
+ import { App, RequestFn as appRequestFn } from '../app';
5
+ export { ErrorType, VerificationUsages, DeviceAuthorizeState } from './consts';
6
+ export { ResponseError } from '../oauthclient';
7
7
  export interface AuthOptions {
8
8
  credentialsClient: AuthClient;
9
9
  captcha: Captcha;
@@ -64,6 +64,7 @@ export declare class Auth {
64
64
  * @return {Promise<SendVerificationCodeResponse>} A Promise<GetVerificationResponse> object.
65
65
  */
66
66
  sendVerificationCode(params: SendVerificationCodeRequest): Promise<SendVerificationCodeResponse>;
67
+ getVerification(params: SendVerificationCodeRequest): Promise<SendVerificationCodeResponse>;
67
68
  /**
68
69
  * Verify the code
69
70
  * @param {VerifyRequest} params A VerifyRequest Object.
@@ -244,5 +245,24 @@ export declare class Auth {
244
245
  * @returns
245
246
  */
246
247
  getProviderSubType(): Promise<ProviderSubType>;
248
+ createCaptchaData(params: {
249
+ state: string;
250
+ redirect_uri?: string;
251
+ }): Promise<{
252
+ captcha_token: string;
253
+ expires_in: number;
254
+ }>;
255
+ /**
256
+ * 验证输入验证码
257
+ * @param params.token 图形验证码token
258
+ * @param params.key 用户输入值
259
+ */
260
+ verifyCaptchaData(params: {
261
+ token: string;
262
+ key: string;
263
+ }): Promise<{
264
+ captcha_token: string;
265
+ expires_in: number;
266
+ }>;
247
267
  private static parseParamsToSearch;
248
268
  }
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Auth = exports.getAuth = exports.DeviceAuthorizeState = exports.VerificationUsages = exports.ErrorType = void 0;
4
4
  const consts_1 = require("./consts");
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "DeviceAuthorizeState", { enumerable: true, get:
13
13
  * Returns the existing `Auth` instance that is associated with the app
14
14
  */
15
15
  function getAuth(app, initOptions) {
16
- return (0, internal_1._getComponent)(app, "auth", () => {
16
+ return (0, internal_1._getComponent)(app, 'auth', () => {
17
17
  const credentialsClient = (0, oauthclient_1.getOAuthClient)(app, initOptions);
18
18
  const baseRequest = credentialsClient.request.bind(credentialsClient);
19
19
  const captcha = (0, captcha_1.getCaptcha)(app, { request: baseRequest });
@@ -43,7 +43,7 @@ class Auth {
43
43
  */
44
44
  async signIn(params) {
45
45
  const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_URL, {
46
- method: "POST",
46
+ method: 'POST',
47
47
  withBasicAuth: true,
48
48
  body: params,
49
49
  });
@@ -56,7 +56,7 @@ class Auth {
56
56
  */
57
57
  async signInAnonymously() {
58
58
  const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL, {
59
- method: "POST",
59
+ method: 'POST',
60
60
  withBasicAuth: true,
61
61
  body: {},
62
62
  });
@@ -70,7 +70,7 @@ class Auth {
70
70
  */
71
71
  async signUp(params) {
72
72
  const data = await this.request(consts_1.ApiUrls.AUTH_SIGN_UP_URL, {
73
- method: "POST",
73
+ method: 'POST',
74
74
  withBasicAuth: true,
75
75
  body: params,
76
76
  });
@@ -89,14 +89,14 @@ class Auth {
89
89
  }
90
90
  try {
91
91
  resp = await this.request(consts_1.ApiUrls.AUTH_SIGNOUT_URL, {
92
- method: "POST",
92
+ method: 'POST',
93
93
  withCredentials: true,
94
94
  body: params,
95
95
  });
96
96
  }
97
97
  catch (err) {
98
98
  if (err.error !== oauthclient_1.ErrorType.UNAUTHENTICATED) {
99
- console.log("sign_out_error", err);
99
+ console.log('sign_out_error', err);
100
100
  }
101
101
  }
102
102
  await this.credentialsClient.setCredentials();
@@ -108,7 +108,7 @@ class Auth {
108
108
  */
109
109
  async revokeAllDevices() {
110
110
  await this.request(consts_1.ApiUrls.AUTH_REVOKE_ALL_URL, {
111
- method: "DELETE",
111
+ method: 'DELETE',
112
112
  withCredentials: true,
113
113
  });
114
114
  }
@@ -118,7 +118,7 @@ class Auth {
118
118
  */
119
119
  async revokeDevice(params) {
120
120
  await this.request(consts_1.ApiUrls.AUTHORIZED_DEVICES_DELETE_URL + params.device_id, {
121
- method: "DELETE",
121
+ method: 'DELETE',
122
122
  withCredentials: true,
123
123
  });
124
124
  }
@@ -131,7 +131,7 @@ class Auth {
131
131
  let withBasicAuth = false;
132
132
  let withCredentials = false;
133
133
  // 发送短信时,如果时给当前用户发,则需要带上鉴权信息
134
- if (params.target == "CUR_USER") {
134
+ if (params.target == 'CUR_USER') {
135
135
  withCredentials = true;
136
136
  }
137
137
  else {
@@ -144,13 +144,16 @@ class Auth {
144
144
  }
145
145
  }
146
146
  return this.request(consts_1.ApiUrls.VERIFICATION_URL, {
147
- method: "POST",
147
+ method: 'POST',
148
148
  withBasicAuth: withBasicAuth,
149
149
  withCredentials: withCredentials,
150
150
  body: params,
151
151
  withCaptcha: true,
152
152
  });
153
153
  }
154
+ async getVerification(params) {
155
+ return this.sendVerificationCode(params);
156
+ }
154
157
  /**
155
158
  * Verify the code
156
159
  * @param {VerifyRequest} params A VerifyRequest Object.
@@ -158,7 +161,7 @@ class Auth {
158
161
  */
159
162
  async verify(params) {
160
163
  return this.request(consts_1.ApiUrls.VERIFY_URL, {
161
- method: "POST",
164
+ method: 'POST',
162
165
  withBasicAuth: true,
163
166
  body: params,
164
167
  });
@@ -169,7 +172,7 @@ class Auth {
169
172
  */
170
173
  async resetPassword(params) {
171
174
  return this.request(consts_1.ApiUrls.RESET_PASSWORD_URL, {
172
- method: "POST",
175
+ method: 'POST',
173
176
  withBasicAuth: true,
174
177
  body: params,
175
178
  });
@@ -189,7 +192,7 @@ class Auth {
189
192
  });
190
193
  }
191
194
  return this.request(url, {
192
- method: "GET",
195
+ method: 'GET',
193
196
  withBasicAuth: true,
194
197
  });
195
198
  }
@@ -200,7 +203,7 @@ class Auth {
200
203
  */
201
204
  async grantProviderToken(params) {
202
205
  return this.request(consts_1.ApiUrls.PROVIDER_TOKEN_URL, {
203
- method: "POST",
206
+ method: 'POST',
204
207
  withBasicAuth: true,
205
208
  body: params,
206
209
  });
@@ -212,7 +215,7 @@ class Auth {
212
215
  */
213
216
  async patchProviderToken(params) {
214
217
  return this.request(consts_1.ApiUrls.PROVIDER_TOKEN_URL, {
215
- method: "PATCH",
218
+ method: 'PATCH',
216
219
  withBasicAuth: true,
217
220
  body: params,
218
221
  });
@@ -224,7 +227,7 @@ class Auth {
224
227
  */
225
228
  async signInWithProvider(params) {
226
229
  const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL, {
227
- method: "POST",
230
+ method: 'POST',
228
231
  withBasicAuth: true,
229
232
  body: params,
230
233
  });
@@ -238,7 +241,7 @@ class Auth {
238
241
  */
239
242
  async bindWithProvider(params) {
240
243
  return this.request(consts_1.ApiUrls.PROVIDER_BIND_URL, {
241
- method: "POST",
244
+ method: 'POST',
242
245
  withBasicAuth: true,
243
246
  body: params,
244
247
  withCredentials: true,
@@ -250,7 +253,7 @@ class Auth {
250
253
  */
251
254
  async getUserProfile() {
252
255
  return this.request(consts_1.ApiUrls.USER_ME_URL, {
253
- method: "GET",
256
+ method: 'GET',
254
257
  withCredentials: true,
255
258
  });
256
259
  }
@@ -260,7 +263,7 @@ class Auth {
260
263
  */
261
264
  async updateUserProfile(params) {
262
265
  return this.request(consts_1.ApiUrls.USER_ME_URL, {
263
- method: "PATCH",
266
+ method: 'PATCH',
264
267
  withCredentials: true,
265
268
  body: params,
266
269
  });
@@ -295,7 +298,7 @@ class Auth {
295
298
  */
296
299
  async transByProvider(params) {
297
300
  return this.request(consts_1.ApiUrls.USER_TRANS_BY_PROVIDER_URL, {
298
- method: "PATCH",
301
+ method: 'PATCH',
299
302
  body: params,
300
303
  withCredentials: true,
301
304
  });
@@ -307,7 +310,7 @@ class Auth {
307
310
  */
308
311
  async grantToken(params) {
309
312
  const credentials = await this.request(consts_1.ApiUrls.AUTH_TOKEN_URL, {
310
- method: "POST",
313
+ method: 'POST',
311
314
  withBasicAuth: true,
312
315
  body: params,
313
316
  });
@@ -320,7 +323,7 @@ class Auth {
320
323
  */
321
324
  async getProviders() {
322
325
  return this.request(consts_1.ApiUrls.PROVIDER_LIST_URL, {
323
- method: "GET",
326
+ method: 'GET',
324
327
  withCredentials: true,
325
328
  });
326
329
  }
@@ -331,7 +334,7 @@ class Auth {
331
334
  async checkIfUserExist(params) {
332
335
  const url = `${consts_1.ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
333
336
  return this.request(url, {
334
- method: "GET",
337
+ method: 'GET',
335
338
  });
336
339
  }
337
340
  /**
@@ -341,7 +344,7 @@ class Auth {
341
344
  */
342
345
  async unbindProvider(params) {
343
346
  return this.request(`${consts_1.ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`, {
344
- method: "DELETE",
347
+ method: 'DELETE',
345
348
  withCredentials: true,
346
349
  });
347
350
  }
@@ -352,7 +355,7 @@ class Auth {
352
355
  */
353
356
  async checkPassword(params) {
354
357
  return this.request(`${consts_1.ApiUrls.SUDO_URL}`, {
355
- method: "POST",
358
+ method: 'POST',
356
359
  withCredentials: true,
357
360
  body: params,
358
361
  });
@@ -364,7 +367,7 @@ class Auth {
364
367
  */
365
368
  async editContact(params) {
366
369
  return this.request(`${consts_1.ApiUrls.EDIT_CONTACT_URL}`, {
367
- method: "PATCH",
370
+ method: 'PATCH',
368
371
  withCredentials: true,
369
372
  body: params,
370
373
  });
@@ -376,7 +379,7 @@ class Auth {
376
379
  */
377
380
  async setPassword(params) {
378
381
  return this.request(`${consts_1.ApiUrls.AUTH_SET_PASSWORD_URL}`, {
379
- method: "PATCH",
382
+ method: 'PATCH',
380
383
  withCredentials: true,
381
384
  body: params,
382
385
  });
@@ -400,7 +403,7 @@ class Auth {
400
403
  */
401
404
  async sudo(params) {
402
405
  return this.request(`${consts_1.ApiUrls.SUDO_URL}`, {
403
- method: "POST",
406
+ method: 'POST',
404
407
  withCredentials: true,
405
408
  body: params,
406
409
  });
@@ -411,9 +414,9 @@ class Auth {
411
414
  * @return {Promise<SendVerificationCodeResponse>} A Promise<SendVerificationCodeResponse> object.
412
415
  */
413
416
  async SendVerificationCodeToCurrentUser(params) {
414
- params.target = "CUR_USER";
417
+ params.target = 'CUR_USER';
415
418
  return this.request(consts_1.ApiUrls.VERIFICATION_URL, {
416
- method: "POST",
419
+ method: 'POST',
417
420
  body: params,
418
421
  withCredentials: true,
419
422
  withCaptcha: true,
@@ -426,7 +429,7 @@ class Auth {
426
429
  */
427
430
  async changeBoundProvider(params) {
428
431
  return this.request(`${consts_1.ApiUrls.PROVIDER_LIST_URL}/${params.provider_id}/trans`, {
429
- method: "POST",
432
+ method: 'POST',
430
433
  body: {
431
434
  provider_trans_token: params.trans_token,
432
435
  },
@@ -440,7 +443,7 @@ class Auth {
440
443
  */
441
444
  async setUserProfile(params) {
442
445
  return this.request(consts_1.ApiUrls.USER_PROFILE_URL, {
443
- method: "PATCH",
446
+ method: 'PATCH',
444
447
  body: params,
445
448
  withCredentials: true,
446
449
  });
@@ -452,7 +455,7 @@ class Auth {
452
455
  async deleteMe(params) {
453
456
  const url = `${consts_1.ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
454
457
  return this.request(url, {
455
- method: "DELETE",
458
+ method: 'DELETE',
456
459
  withCredentials: true,
457
460
  });
458
461
  }
@@ -471,13 +474,13 @@ class Auth {
471
474
  const customSignTicketFn = this._getCustomSignTicketFn;
472
475
  if (!customSignTicketFn) {
473
476
  return Promise.reject({
474
- error: "failed_precondition",
475
- error_description: "please use setCustomSignFunc to set custom sign function",
477
+ error: 'failed_precondition',
478
+ error_description: 'please use setCustomSignFunc to set custom sign function',
476
479
  });
477
480
  }
478
481
  const customTicket = await customSignTicketFn();
479
482
  return this.signInWithProvider({
480
- provider_id: "custom",
483
+ provider_id: 'custom',
481
484
  provider_token: customTicket,
482
485
  });
483
486
  }
@@ -488,7 +491,7 @@ class Auth {
488
491
  async queryUserProfile(params) {
489
492
  const url = `${consts_1.ApiUrls.USER_QUERY_URL}?${Auth.parseParamsToSearch(params)}`;
490
493
  return this.request(url, {
491
- method: "GET",
494
+ method: 'GET',
492
495
  withCredentials: true,
493
496
  });
494
497
  }
@@ -499,7 +502,7 @@ class Auth {
499
502
  */
500
503
  async authorize(params) {
501
504
  return this.request(consts_1.ApiUrls.AUTHORIZE_URL, {
502
- method: "POST",
505
+ method: 'POST',
503
506
  withCredentials: true,
504
507
  body: params,
505
508
  });
@@ -510,14 +513,14 @@ class Auth {
510
513
  */
511
514
  async authorizeDevice(params) {
512
515
  return this.request(consts_1.ApiUrls.AUTHORIZE_DEVICE_URL, {
513
- method: "POST",
516
+ method: 'POST',
514
517
  withCredentials: true,
515
518
  body: params,
516
519
  });
517
520
  }
518
521
  async deviceAuthorize(params) {
519
522
  return this.request(consts_1.ApiUrls.AUTHORIZE_DEVICE_CODE_URL, {
520
- method: "POST",
523
+ method: 'POST',
521
524
  withBasicAuth: true,
522
525
  body: params,
523
526
  });
@@ -537,7 +540,7 @@ class Auth {
537
540
  withBasicAuth = false;
538
541
  }
539
542
  return this.request(url, {
540
- method: "GET",
543
+ method: 'GET',
541
544
  withBasicAuth: withBasicAuth,
542
545
  withCredentials: withCredentials,
543
546
  });
@@ -554,6 +557,25 @@ class Auth {
554
557
  },
555
558
  });
556
559
  }
560
+ async createCaptchaData(params) {
561
+ return this.request(consts_1.ApiUrls.CAPTCHA_DATA_URL, {
562
+ method: 'POST',
563
+ withBasicAuth: true,
564
+ body: params,
565
+ });
566
+ }
567
+ /**
568
+ * 验证输入验证码
569
+ * @param params.token 图形验证码token
570
+ * @param params.key 用户输入值
571
+ */
572
+ async verifyCaptchaData(params) {
573
+ return this.request(consts_1.ApiUrls.VERIFY_CAPTCHA_DATA_URL, {
574
+ method: 'POST',
575
+ withBasicAuth: true,
576
+ body: params,
577
+ });
578
+ }
557
579
  static parseParamsToSearch(params) {
558
580
  for (let key in params) {
559
581
  if (!params[key]) {
@@ -565,4 +587,3 @@ class Auth {
565
587
  }
566
588
  }
567
589
  exports.Auth = Auth;
568
- //# sourceMappingURL=index.js.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=models.js.map
@@ -1,8 +1,9 @@
1
- import { App, RequestOptions, RequestFn, Storage, OpenURIWithCallback } from "../app";
1
+ import { App, RequestOptions, RequestFn, Storage, OpenURIWithCallback } from '../app';
2
2
  export interface CaptchaOptions {
3
+ clientId?: string;
3
4
  request: RequestFn;
4
5
  storage: Storage;
5
- openURIWithCallback: OpenURIWithCallback;
6
+ openURIWithCallback?: OpenURIWithCallback;
6
7
  }
7
8
  export interface CaptchaInitOptions {
8
9
  request?: RequestFn;
@@ -22,8 +23,8 @@ export interface GetCaptchaResponse {
22
23
  url?: string;
23
24
  }
24
25
  export declare class Captcha {
25
- private _config;
26
- private _tokenSectionName;
26
+ private config;
27
+ private tokenSectionName;
27
28
  /**
28
29
  * constructor
29
30
  * @param {CaptchaOptions} opts
@@ -36,10 +37,10 @@ export declare class Captcha {
36
37
  */
37
38
  request<T>(url: string, options?: CaptchaRequestOptions): Promise<T>;
38
39
  /**
39
- * _getCaptchaToken get captcha token
40
+ * getCaptchaToken 获取captchaToken
40
41
  */
41
- private _getCaptchaToken;
42
- private _appendCaptchaTokenToURL;
43
- private _saveCaptchaToken;
44
- private _findCaptchaToken;
42
+ private getCaptchaToken;
43
+ private appendCaptchaTokenToURL;
44
+ private saveCaptchaToken;
45
+ private findCaptchaToken;
45
46
  }