@cloudbase/oauth 0.1.1-alpha → 1.0.0-alpha.0

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 (97) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +26 -0
  3. package/Dockerfile +15 -0
  4. package/README.md +130 -100
  5. package/_exmaple/assets/scripts/function/function.ts +99 -0
  6. package/_exmaple/assets/scripts/index.ts +101 -0
  7. package/_exmaple/assets/scripts/request.ts +11 -0
  8. package/_exmaple/index.html +15 -0
  9. package/_exmaple/package.json +33 -0
  10. package/_exmaple/tsconfig.json +71 -0
  11. package/_exmaple/typings.d.ts +0 -0
  12. package/_exmaple/webpack.config.js +42 -0
  13. package/dist/auth/apis.d.ts +51 -0
  14. package/dist/auth/apis.js +519 -0
  15. package/{auth → dist/auth}/consts.d.ts +6 -2
  16. package/dist/auth/consts.js +60 -0
  17. package/dist/auth/models.d.ts +354 -0
  18. package/dist/auth/models.js +3 -0
  19. package/dist/captcha/captcha.d.ts +35 -0
  20. package/dist/captcha/captcha.js +262 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.js +63 -0
  23. package/{oauthclient → dist/oauth2client}/consts.d.ts +22 -1
  24. package/dist/oauth2client/consts.js +73 -0
  25. package/dist/oauth2client/interface.d.ts +15 -0
  26. package/dist/oauth2client/interface.js +10 -0
  27. package/{oauthclient → dist/oauth2client}/models.d.ts +13 -5
  28. package/dist/oauth2client/models.js +3 -0
  29. package/dist/oauth2client/oauth2client.d.ts +70 -0
  30. package/dist/oauth2client/oauth2client.js +618 -0
  31. package/dist/utils/function/single-promise.d.ts +5 -0
  32. package/dist/utils/function/single-promise.js +89 -0
  33. package/dist/utils/uuid.d.ts +1 -0
  34. package/dist/utils/uuid.js +12 -0
  35. package/package.json +28 -29
  36. package/publish.sh +2 -0
  37. package/src/auth/apis.ts +597 -0
  38. package/src/auth/consts.ts +56 -0
  39. package/src/auth/models.ts +432 -0
  40. package/src/captcha/captcha.ts +217 -0
  41. package/src/index.ts +49 -0
  42. package/src/oauth2client/consts.ts +69 -0
  43. package/src/oauth2client/interface.ts +57 -0
  44. package/src/oauth2client/models.ts +61 -0
  45. package/src/oauth2client/oauth2client.ts +606 -0
  46. package/src/utils/function/single-promise.ts +40 -0
  47. package/src/utils/uuid.ts +11 -0
  48. package/tsconfig.json +44 -0
  49. package/wiki/README.md +75 -0
  50. package/app/index.d.ts +0 -28
  51. package/app/index.js +0 -54
  52. package/app/index.js.map +0 -1
  53. package/app/internal.d.ts +0 -12
  54. package/app/internal.js +0 -25
  55. package/app/internal.js.map +0 -1
  56. package/app/openuri.d.ts +0 -20
  57. package/app/openuri.js +0 -104
  58. package/app/openuri.js.map +0 -1
  59. package/app/request.d.ts +0 -18
  60. package/app/request.js +0 -44
  61. package/app/request.js.map +0 -1
  62. package/app/storage.d.ts +0 -41
  63. package/app/storage.js +0 -35
  64. package/app/storage.js.map +0 -1
  65. package/auth/consts.js +0 -57
  66. package/auth/consts.js.map +0 -1
  67. package/auth/index.d.ts +0 -193
  68. package/auth/index.js +0 -403
  69. package/auth/index.js.map +0 -1
  70. package/auth/models.d.ts +0 -158
  71. package/auth/models.js +0 -3
  72. package/auth/models.js.map +0 -1
  73. package/captcha/index.d.ts +0 -45
  74. package/captcha/index.js +0 -133
  75. package/captcha/index.js.map +0 -1
  76. package/index.d.ts +0 -8
  77. package/index.js +0 -17
  78. package/index.js.map +0 -1
  79. package/oauthclient/consts.js +0 -53
  80. package/oauthclient/consts.js.map +0 -1
  81. package/oauthclient/index.d.ts +0 -18
  82. package/oauthclient/index.js +0 -21
  83. package/oauthclient/index.js.map +0 -1
  84. package/oauthclient/interface.d.ts +0 -25
  85. package/oauthclient/interface.js +0 -10
  86. package/oauthclient/interface.js.map +0 -1
  87. package/oauthclient/models.js +0 -3
  88. package/oauthclient/models.js.map +0 -1
  89. package/oauthclient/oauthclient.d.ts +0 -142
  90. package/oauthclient/oauthclient.js +0 -399
  91. package/oauthclient/oauthclient.js.map +0 -1
  92. package/utils/single-promise.d.ts +0 -18
  93. package/utils/single-promise.js +0 -48
  94. package/utils/single-promise.js.map +0 -1
  95. package/utils/uuid.d.ts +0 -5
  96. package/utils/uuid.js +0 -16
  97. package/utils/uuid.js.map +0 -1
@@ -0,0 +1,597 @@
1
+ 'use strict';
2
+
3
+ import { ApiUrls } from './consts';
4
+ import {
5
+ GetVerificationRequest,
6
+ GetVerificationResponse,
7
+ UserProfile,
8
+ UserInfo,
9
+ SignInRequest,
10
+ SignUpRequest,
11
+ VerifyRequest,
12
+ VerifyResponse,
13
+ GenProviderRedirectUriRequest,
14
+ GenProviderRedirectUriResponse,
15
+ GrantProviderTokenRequest,
16
+ GrantProviderTokenResponse,
17
+ PatchProviderTokenRequest,
18
+ PatchProviderTokenResponse,
19
+ SignInWithProviderRequest,
20
+ BindWithProviderRequest,
21
+ TransByProviderRequest,
22
+ GrantTokenRequest,
23
+ UserProfileProvider,
24
+ UnbindProviderRequest,
25
+ CheckPasswordrRequest,
26
+ BindPhoneRequest,
27
+ BindEmailRequest,
28
+ SetPasswordRequest,
29
+ ChangeBindedProviderRequest,
30
+ ChangeBindedProviderResponse,
31
+ UpdatePasswordRequest,
32
+ SudoResponse,
33
+ SudoRequest,
34
+ GetCustomSignTicketFn,
35
+ QueryUserProfileRequest,
36
+ QueryUserProfileResponse,
37
+ ResetPasswordRequest,
38
+ DeviceAuthorizeRequest,
39
+ DeviceAuthorizeResponse,
40
+ CheckUsernameRequest
41
+ } from './models';
42
+ import { SimpleStorage, RequestFunction } from '../oauth2client/interface';
43
+ import { OAuth2Client, defaultStorage } from '../oauth2client/oauth2client';
44
+ import { Credentials } from '../oauth2client/models';
45
+ import { Captcha } from '../captcha/captcha';
46
+
47
+
48
+ export interface AuthOptions {
49
+ apiOrigin: string;
50
+ clientId: string;
51
+ credentialsClient?: OAuth2Client;
52
+ request?: RequestFunction;
53
+ storage?: SimpleStorage;
54
+ }
55
+
56
+ /**
57
+ * Auth
58
+ */
59
+ export class Auth {
60
+ private _config: AuthOptions;
61
+ private _getCustomSignTicketFn?: GetCustomSignTicketFn;
62
+
63
+
64
+ /**
65
+ * constructor
66
+ * @param {AuthOptions} opts
67
+ */
68
+ constructor(opts: AuthOptions) {
69
+ let request = opts.request;
70
+ let oAuth2Client = opts.credentialsClient;
71
+ if (!oAuth2Client) {
72
+ const initOptions = {
73
+ apiOrigin: opts.apiOrigin,
74
+ clientId: opts.clientId,
75
+ storage: opts.storage,
76
+ };
77
+ oAuth2Client = new OAuth2Client(initOptions);
78
+ }
79
+ if (!request) {
80
+ const baseRequest = oAuth2Client.request.bind(oAuth2Client);
81
+ const captcha = new Captcha({
82
+ clientId: opts.clientId,
83
+ request: baseRequest,
84
+ storage: opts.storage,
85
+ })
86
+ request = captcha.request.bind(captcha)
87
+ }
88
+ this._config = {
89
+ apiOrigin: opts.apiOrigin,
90
+ clientId: opts.clientId,
91
+ request: request,
92
+ credentialsClient: oAuth2Client,
93
+ storage: opts.storage || defaultStorage,
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Sign in.
99
+ * @param {SignInRequest} params A SignInRequest Object.
100
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
101
+ */
102
+ public async signIn(params: SignInRequest): Promise<Credentials> {
103
+ const credentials: Credentials = await this._config.request<Credentials>(
104
+ ApiUrls.AUTH_SIGN_IN_URL,
105
+ {
106
+ method: 'POST',
107
+ body: params
108
+ },
109
+ );
110
+ await this._config.credentialsClient.setCredentials(credentials);
111
+ return Promise.resolve(credentials);
112
+ }
113
+
114
+ /**
115
+ * Sign in Anonymously
116
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
117
+ */
118
+ public async signInAnonymously(): Promise<Credentials> {
119
+ const credentials: Credentials = await this._config.request<Credentials>(
120
+ ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,
121
+ {
122
+ method: 'POST',
123
+ body: {}
124
+ },
125
+ );
126
+ await this._config.credentialsClient.setCredentials(credentials);
127
+ return Promise.resolve(credentials);
128
+ }
129
+
130
+ /**
131
+ * Sign up.
132
+ * @param {SignUpRequest} params A SignUpRequest Object.
133
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
134
+ */
135
+ public async signUp(params: SignUpRequest): Promise<Credentials> {
136
+ const data: Credentials = await this._config.request<Credentials>(
137
+ ApiUrls.AUTH_SIGN_UP_URL,
138
+ {
139
+ method: 'POST',
140
+ body: params,
141
+ },
142
+ );
143
+ await this._config.credentialsClient.setCredentials(data);
144
+ return Promise.resolve(data);
145
+ }
146
+
147
+ /**
148
+ * Sign out.
149
+ * @return {Object} A Promise<void> object.
150
+ */
151
+ public async signOut(): Promise<any> {
152
+ const accessToken: string = await this._config.credentialsClient.getAccessToken();
153
+ const data = await this._config.request(ApiUrls.AUTH_REVOKE_URL, {
154
+ method: 'POST',
155
+ body: {
156
+ token: accessToken,
157
+ },
158
+ });
159
+ await this._config.credentialsClient.setCredentials();
160
+ return Promise.resolve(data);
161
+ }
162
+
163
+ /**
164
+ * Get the verification.
165
+ * @param {GetVerificationRequest} params A GetVerificationRequest Object.
166
+ * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
167
+ */
168
+ public async getVerification(
169
+ params: GetVerificationRequest,
170
+ ): Promise<GetVerificationResponse> {
171
+ return this._config.request<GetVerificationResponse>(
172
+ ApiUrls.VERIFICATION_URL,
173
+ {
174
+ method: 'POST',
175
+ body: params,
176
+ withCaptcha: true
177
+ },
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Verify the code
183
+ * @param {VerifyRequest} params A VerifyRequest Object.
184
+ * @return {Promise<VerifyResponse>} A Promise<VerifyResponse> object.
185
+ */
186
+ public async verify(params: VerifyRequest): Promise<VerifyResponse> {
187
+ return this._config.request<VerifyResponse>(ApiUrls.VERIFY_URL, {
188
+ method: 'POST',
189
+ body: params,
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Gen provider redirect uri.
195
+ * @param {GenProviderRedirectUriRequest} params A GenProviderRedirectUriRequest object.
196
+ * @return {Promise<GenProviderRedirectUriResponse>} A Promise<GenProviderRedirectUriResponse> object.
197
+ */
198
+ public async genProviderRedirectUri(
199
+ params: GenProviderRedirectUriRequest,
200
+ ): Promise<GenProviderRedirectUriResponse> {
201
+ let url = `${ApiUrls.PROVIDER_URI_URL}?client_id=${this._config.clientId
202
+ }&provider_id=${params.provider_id}&redirect_uri=${encodeURIComponent(
203
+ params.provider_redirect_uri,
204
+ )}&state=${params.state}`;
205
+ const other_params = params.other_params;
206
+ if (other_params) {
207
+ if (
208
+ typeof other_params.sign_out_uri === 'string' &&
209
+ other_params.sign_out_uri.length > 0
210
+ ) {
211
+ url += `&other_params[sign_out_uri]=${other_params.sign_out_uri}`;
212
+ }
213
+ }
214
+ return this._config.request<GenProviderRedirectUriResponse>(url, {
215
+ method: 'GET',
216
+ });
217
+ }
218
+
219
+ /**
220
+ * Grant provider token.
221
+ * @param {GrantProviderTokenRequest} params A GrantProviderTokenRequest object.
222
+ * @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
223
+ */
224
+ public async grantProviderToken(
225
+ params: GrantProviderTokenRequest,
226
+ ): Promise<GrantProviderTokenResponse> {
227
+ return this._config.request<GrantProviderTokenResponse>(
228
+ ApiUrls.PROVIDER_TOKEN_URL,
229
+ {
230
+ method: 'POST',
231
+ body: params,
232
+ },
233
+ );
234
+ }
235
+
236
+ /**
237
+ * Grant provider token.
238
+ * @param {PatchProviderTokenRequest} params A PatchProviderTokenRequest object.
239
+ * @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
240
+ */
241
+ public async patchProviderToken(
242
+ params: PatchProviderTokenRequest,
243
+ ): Promise<PatchProviderTokenResponse> {
244
+ return this._config.request<PatchProviderTokenResponse>(
245
+ ApiUrls.PROVIDER_TOKEN_URL,
246
+ {
247
+ method: 'PATCH',
248
+ body: params,
249
+ },
250
+ );
251
+ }
252
+
253
+ /**
254
+ * Signin with provider request.
255
+ * @param {SignInWithProviderRequest} params A SignInWithProviderRequest object.
256
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
257
+ */
258
+ public async signInWithProvider(
259
+ params: SignInWithProviderRequest,
260
+ ): Promise<Credentials> {
261
+ const credentials: Credentials = await this._config.request<Credentials>(
262
+ ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL,
263
+ {
264
+ method: 'POST',
265
+ body: params,
266
+ },
267
+ );
268
+ await this._config.credentialsClient.setCredentials(credentials);
269
+ return Promise.resolve(credentials);
270
+ }
271
+
272
+ /**
273
+ * Bind with provider
274
+ * @param {BindWithProviderRequest} params A BindWithProviderRequest object.
275
+ * @return {Promise<void>} A Promise<any> object.
276
+ */
277
+ public async bindWithProvider(
278
+ params: BindWithProviderRequest,
279
+ ): Promise<void> {
280
+ return this._config.request<any>(ApiUrls.PROVIDER_BIND_URL, {
281
+ method: 'POST',
282
+ body: params,
283
+ withCredentials: true,
284
+ });
285
+ }
286
+
287
+ /**
288
+ * Get the user profile.
289
+ * @return {Promise<UserProfile>} A Promise<UserProfile> object.
290
+ */
291
+ public async getUserProfile(): Promise<UserProfile> {
292
+ return this.getUserInfo();
293
+ }
294
+
295
+ /**
296
+ * Get the user info.
297
+ * @return {Promise<UserInfo>} A Promise<UserProfile> object.
298
+ */
299
+ public async getUserInfo(): Promise<UserInfo> {
300
+ const userInfo = await this._config.request<UserInfo>(ApiUrls.USER_ME_URL, {
301
+ method: 'GET',
302
+ withCredentials: true,
303
+ });
304
+ if (userInfo.picture) {
305
+ userInfo.avatarUrl = userInfo.picture;
306
+ }
307
+
308
+ if (userInfo.sub) {
309
+ userInfo.uid = userInfo.sub
310
+ }
311
+
312
+ return userInfo;
313
+ }
314
+
315
+ /**
316
+ * hasLoginState check if has login state
317
+ * @return {Promise<boolean>} A Promise<boolean> object.
318
+ */
319
+ public async hasLoginState(): Promise<boolean> {
320
+ try {
321
+ await this._config.credentialsClient.getAccessToken()
322
+ return true
323
+ } catch (error) {
324
+ return false
325
+ }
326
+ }
327
+
328
+ public hasLoginStateSync(): Credentials | null {
329
+ const credentials = this._config.credentialsClient.getCredentialsSync()
330
+ return credentials
331
+ }
332
+
333
+ public async getLoginState(): Promise<Credentials | null> {
334
+ return this._config.credentialsClient.getCredentialsAsync()
335
+ }
336
+
337
+ /**
338
+ * Trans by provider.
339
+ * @param {TransByProviderRequest} params A TransByProviderRequest object.
340
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
341
+ */
342
+ public async transByProvider(
343
+ params: TransByProviderRequest,
344
+ ): Promise<Credentials> {
345
+ return this._config.request<Credentials>(
346
+ ApiUrls.USER_TRANS_BY_PROVIDER_URL,
347
+ {
348
+ method: 'PATCH',
349
+ body: params,
350
+ withCredentials: true,
351
+ },
352
+ );
353
+ }
354
+
355
+ /**
356
+ * Grant token.
357
+ * @param {GrantTokenRequest} params A GrantTokenRequest object.
358
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
359
+ */
360
+ public async grantToken(params: GrantTokenRequest): Promise<Credentials> {
361
+ return this._config.request<Credentials>(ApiUrls.AUTH_TOKEN_URL, {
362
+ method: 'POST',
363
+ body: params,
364
+ });
365
+ }
366
+
367
+ /**
368
+ * Get the provide list.
369
+ * @return {Promise<UserProfileProvider>} A Promise<UserProfileProvider> object.
370
+ */
371
+ public async getProviders(): Promise<UserProfileProvider> {
372
+ return this._config.request<UserProfileProvider>(ApiUrls.PROVIDER_LIST, {
373
+ method: 'GET',
374
+ withCredentials: true,
375
+ });
376
+ }
377
+
378
+ /**
379
+ * unbind provider.
380
+ * @param {UnbindProviderRequest} params
381
+ * @return {Promise<any>}
382
+ */
383
+ public async unbindProvider(params: UnbindProviderRequest): Promise<void> {
384
+ return this._config.request<any>(
385
+ `${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`,
386
+ {
387
+ method: 'DELETE',
388
+ withCredentials: true,
389
+ },
390
+ );
391
+ }
392
+
393
+ /**
394
+ * check Password.
395
+ * @param {CheckPasswordrRequest} params
396
+ * @return {Promise<any>}
397
+ */
398
+ public async checkPassword(params: CheckPasswordrRequest): Promise<void> {
399
+ return this._config.request<any>(`${ApiUrls.CHECK_PWD_URL}`, {
400
+ method: 'POST',
401
+ withCredentials: true,
402
+ body: params,
403
+ });
404
+ }
405
+
406
+ /**
407
+ * check Password.
408
+ * @param {CheckPasswordrRequest} params
409
+ * @return {Promise<any>}
410
+ */
411
+ public async bindPhone(params: BindPhoneRequest): Promise<void> {
412
+ return this._config.request<any>(`${ApiUrls.BIND_CONTACT_URL}`, {
413
+ method: 'PATCH',
414
+ withCredentials: true,
415
+ body: params,
416
+ });
417
+ }
418
+
419
+ /**
420
+ * check Password.
421
+ * @param {CheckPasswordrRequest} params
422
+ * @return {Promise<any>}
423
+ */
424
+ public async bindEmail(params: BindEmailRequest): Promise<void> {
425
+ return this._config.request<any>(`${ApiUrls.BIND_CONTACT_URL}`, {
426
+ method: 'PATCH',
427
+ withCredentials: true,
428
+ body: params,
429
+ });
430
+ }
431
+
432
+ /**
433
+ * Set Password.
434
+ * @param {SetPasswordrRequest} params
435
+ * @return {Promise<any>}
436
+ */
437
+ public async setPassword(params: SetPasswordRequest): Promise<void> {
438
+ return this._config.request<any>(`${ApiUrls.AUTH_SET_PASSWORD}`, {
439
+ method: 'PATCH',
440
+ withCredentials: true,
441
+ body: params,
442
+ });
443
+ }
444
+
445
+ /**
446
+ * updatePasswordByOld 使用旧密码修改密码,如果已经绑定手机号,请先:sudo,再修改密码
447
+ * @param {SetPasswordrRequest} params
448
+ * @return {Promise<any>}
449
+ */
450
+ public async updatePasswordByOld(params: UpdatePasswordRequest): Promise<void> {
451
+ const sudoToken = await this.sudo({ password: params.old_password })
452
+ return this.setPassword({
453
+ sudo_token: sudoToken.sudo_token,
454
+ new_password: params.new_password,
455
+ })
456
+ }
457
+
458
+
459
+ /**
460
+ * sudo
461
+ * @param {sudo} params
462
+ * @return {Promise<any>}
463
+ */
464
+ public async sudo(params: SudoRequest): Promise<SudoResponse> {
465
+ return this._config.request<SudoResponse>(`${ApiUrls.SUDO_URL}`, {
466
+ method: 'POST',
467
+ withCredentials: true,
468
+ body: params,
469
+ });
470
+ }
471
+
472
+ /**
473
+ * Get the current user verification.
474
+ * @param {GetVerificationRequest} params A GetVerificationRequest Object.
475
+ * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
476
+ */
477
+ public async getCurUserVerification(
478
+ params: GetVerificationRequest,
479
+ ): Promise<GetVerificationResponse> {
480
+ params.target = 'CUR_USER';
481
+ return this._config.request<GetVerificationResponse>(
482
+ ApiUrls.VERIFICATION_URL,
483
+ {
484
+ method: 'POST',
485
+ body: params,
486
+ withCredentials: true,
487
+ withCaptcha: true
488
+ },
489
+ );
490
+ }
491
+
492
+ /**
493
+ * change binded provider.
494
+ * @param {GetVerificationRequest} params A GetVerificationRequest Object.
495
+ * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
496
+ */
497
+ public async changeBindedProvider(
498
+ params: ChangeBindedProviderRequest,
499
+ ): Promise<ChangeBindedProviderResponse> {
500
+ return this._config.request<ChangeBindedProviderResponse>(
501
+ `${ApiUrls.PROVIDER_LIST}/${params.provider_id}/trans`,
502
+ {
503
+ method: 'POST',
504
+ body: {
505
+ provider_trans_token: params.trans_token,
506
+ },
507
+ withCredentials: true,
508
+ },
509
+ );
510
+ }
511
+
512
+ /**
513
+ * Patch the user profile.
514
+ * @param {UserProfile} params A UserProfile Object.
515
+ * @return {Promise<UserProfile>} A Promise<UserProfile> object.
516
+ */
517
+ public async setUserProfile(params: UserProfile): Promise<UserProfile> {
518
+ return this._config.request<UserProfile>(ApiUrls.USER_PRIFILE_URL, {
519
+ method: 'PATCH',
520
+ body: params,
521
+ withCredentials: true,
522
+ });
523
+ }
524
+
525
+ /**
526
+ * Patch the user profile.
527
+ * @param {QueryUserProfileReq} appended_params A QueryUserProfileReq Object.
528
+ * @return {Promise<UserProfile>} A Promise<UserProfile> object.
529
+ */
530
+ public async queryUserProfile(
531
+ params: QueryUserProfileRequest,
532
+ ): Promise<QueryUserProfileResponse> {
533
+ let url = new URL(ApiUrls.USER_QUERY_URL);
534
+ const searchParams = new URLSearchParams(params as any);
535
+ url.search = searchParams.toString();
536
+ return this._config.request<QueryUserProfileResponse>(url.toString(), {
537
+ method: 'GET',
538
+ withCredentials: true,
539
+ });
540
+ }
541
+
542
+ /**
543
+ * setCustomSignFunc set the get ticket function
544
+ * @param getTickFn
545
+ */
546
+ public setCustomSignFunc(getTickFn: GetCustomSignTicketFn) {
547
+ this._getCustomSignTicketFn = getTickFn
548
+ }
549
+
550
+ /**
551
+ * SignInWithCustomTicket custom signIn
552
+ * @constructor
553
+ */
554
+ public async signInWithCustomTicket(): Promise<Credentials> {
555
+ const customTicket = await this._getCustomSignTicketFn()
556
+ return this.signInWithProvider({
557
+ provider_id: 'custom',
558
+ provider_token: customTicket
559
+ })
560
+ }
561
+
562
+ /**
563
+ * Reset password
564
+ * @param {ResetPasswordRequest} params
565
+ * @returns {Promise<void>}
566
+ * @memberof Auth
567
+ */
568
+ public async resetPassword(params: ResetPasswordRequest): Promise<void> {
569
+ return this._config.request(ApiUrls.AUTH_SET_PASSWORD, {
570
+ method: 'POST',
571
+ body: params,
572
+ withCredentials: true
573
+ })
574
+ }
575
+
576
+ /**
577
+ * device authorization
578
+ * @param {DeviceAuthorizeRequest} params
579
+ * @returns {Promise<DeviceAuthorizeResponse>}
580
+ * @memberof Auth
581
+ */
582
+ public async deviceAuthorize(params: DeviceAuthorizeRequest): Promise<DeviceAuthorizeResponse> {
583
+ return this._config.request(ApiUrls.AUTH_GET_DEVICE_CODE, {
584
+ method: 'POST',
585
+ body: params,
586
+ withCredentials: true
587
+ })
588
+ }
589
+
590
+ public async checkUsername(params: CheckUsernameRequest): Promise<void> {
591
+ return this._config.request(ApiUrls.AUTH_GET_DEVICE_CODE, {
592
+ method: 'GET',
593
+ body: params,
594
+ withCredentials: true
595
+ })
596
+ }
597
+ }
@@ -0,0 +1,56 @@
1
+ export enum ApiUrls {
2
+ AUTH_SIGN_IN_URL = '/auth/v1/signin',
3
+ AUTH_SIGN_IN_ANONYMOUSLY_URL = '/auth/v1/signin/anonymously',
4
+ AUTH_SIGN_IN_WITH_PROVIDER_URL = '/auth/v1/signin/with/provider',
5
+ AUTH_SIGN_UP_URL = '/auth/v1/signup',
6
+ AUTH_TOKEN_URL = '/auth/v1/token',
7
+ AUTH_REVOKE_URL = '/auth/v1/revoke',
8
+ PROVIDER_BIND_URL = '/auth/v1/user/provider/bind',
9
+ PROVIDER_TOKEN_URL = '/auth/v1/provider/token',
10
+ PROVIDER_URI_URL = '/auth/v1/provider/uri',
11
+ USER_ME_URL = '/auth/v1/user/me',
12
+ USER_QUERY_URL = '/auth/v1/user/query',
13
+ USER_PRIFILE_URL = '/auth/v1/user/profile',
14
+ USER_TRANS_BY_PROVIDER_URL = '/auth/v1/user/trans/by/provider',
15
+ VERIFICATION_URL = '/auth/v1/verification',
16
+ VERIFY_URL = '/auth/v1/verification/verify',
17
+ PROVIDER_LIST = '/auth/v1/user/provider',
18
+ PROVIDER_UNBIND_URL = '/auth/v1/user/provider',
19
+ CHECK_PWD_URL = '/auth/v1/user/sudo',
20
+ SUDO_URL = '/auth/v1/user/sudo',
21
+ BIND_CONTACT_URL = '/auth/v1/user/contact',
22
+ AUTH_SET_PASSWORD = '/auth/v1/user/password',
23
+ AUTH_RESET_PASSWORD = '/auth/v1/reset',
24
+ AUTH_GET_DEVICE_CODE = '/auth/v1/device/code',
25
+ CHECK_USERNAME = '/auth/v1/checkUsername'
26
+ }
27
+
28
+ export enum VerificationUsages {
29
+ REGISTER = 'REGISTER',
30
+ SIGN_IN = 'SIGN_IN',
31
+ PASSWORD_RESET = 'PASSWORD_RESET',
32
+ EMAIL_ADDRESS_CHANGE = 'EMAIL_ADDRESS_CHANGE',
33
+ PHONE_NUMBER_CHANGE = 'PHONE_NUMBER_CHANGE',
34
+ }
35
+
36
+ export enum ErrorType {
37
+ INVALID_ARGUMENT = 'invalid_argument',
38
+ DEADLINE_EXCEEDED = 'deadline_exceeded',
39
+ NOT_FOUND = 'not_found',
40
+ ALREADY_EXISTS = 'already_exists',
41
+ PERMISSION_DENIED = 'permission_denied',
42
+ ABORTED = 'aborted',
43
+ OUT_OF_RANGE = 'out_of_range',
44
+ UNIMPLEMENTED = 'unimplemented',
45
+ INTERNAL = 'internal',
46
+ UNAVAILABLE = 'unavailable',
47
+ DATA_LOSS = 'data_loss',
48
+ // CommonError
49
+ CAPTCHA_REQUIRED = 'captcha_required',
50
+ CAPTCHA_INVALID = 'captcha_invalid',
51
+ INVALID_PASSWORD = 'invalid_password',
52
+ PASSWORD_NOT_SET = 'password_not_set',
53
+ INVALID_STATUS = 'invalid_status',
54
+ USER_PENDING = 'user_pending',
55
+ USER_BLOCKED = 'user_blocked',
56
+ }