@cloudbase/oauth 0.1.1-alpha.7 → 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.
- package/dist/app/index.d.ts +7 -4
- package/dist/app/index.js +7 -4
- package/dist/app/internal.js +0 -1
- package/dist/app/openuri.d.ts +1 -0
- package/dist/app/openuri.js +10 -8
- package/dist/app/request.js +0 -1
- package/dist/app/storage.js +0 -1
- package/dist/auth/consts.d.ts +3 -0
- package/dist/auth/consts.js +3 -1
- package/dist/auth/index.d.ts +26 -6
- package/dist/auth/index.js +64 -43
- package/dist/auth/models.js +0 -1
- package/dist/captcha/index.d.ts +10 -9
- package/dist/captcha/index.js +69 -50
- package/dist/function/index.js +0 -1
- package/dist/index.js +0 -1
- package/dist/oauthclient/consts.js +0 -1
- package/dist/oauthclient/index.js +0 -1
- package/dist/oauthclient/interface.js +0 -1
- package/dist/oauthclient/models.js +0 -1
- package/dist/oauthclient/oauthclient.js +0 -1
- package/dist/package.json +1 -1
- package/dist/utils/base64.js +0 -1
- package/dist/utils/mp.d.ts +2 -0
- package/dist/utils/mp.js +57 -0
- package/dist/utils/promise.js +0 -1
- package/dist/utils/uuid.js +0 -1
- package/package.json +1 -1
- package/src/app/index.ts +64 -64
- package/src/app/openuri.ts +14 -7
- package/src/auth/consts.ts +69 -66
- package/src/auth/index.ts +156 -209
- package/src/captcha/index.ts +165 -138
- package/src/utils/mp.ts +55 -0
- package/tsconfig.json +5 -18
- package/dist/app/index.js.map +0 -1
- package/dist/app/internal.js.map +0 -1
- package/dist/app/openuri.js.map +0 -1
- package/dist/app/request.js.map +0 -1
- package/dist/app/storage.js.map +0 -1
- package/dist/auth/consts.js.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/models.js.map +0 -1
- package/dist/captcha/index.js.map +0 -1
- package/dist/function/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/oauthclient/consts.js.map +0 -1
- package/dist/oauthclient/index.js.map +0 -1
- package/dist/oauthclient/interface.js.map +0 -1
- package/dist/oauthclient/models.js.map +0 -1
- package/dist/oauthclient/oauthclient.js.map +0 -1
- package/dist/utils/base64.js.map +0 -1
- package/dist/utils/promise.js.map +0 -1
- package/dist/utils/uuid.js.map +0 -1
package/src/auth/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { ApiUrls } from
|
|
1
|
+
'use strict';
|
|
2
|
+
import { ApiUrls } from './consts';
|
|
3
3
|
import {
|
|
4
4
|
UserProfile,
|
|
5
5
|
SignInRequest,
|
|
@@ -45,21 +45,15 @@ import {
|
|
|
45
45
|
SignoutRequest,
|
|
46
46
|
SignoutReponse,
|
|
47
47
|
ProviderSubType,
|
|
48
|
-
} from
|
|
48
|
+
} from './models';
|
|
49
49
|
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} from
|
|
57
|
-
import { getCaptcha, Captcha } from "../captcha";
|
|
58
|
-
import { App, RequestFn as appRequestFn } from "../app";
|
|
59
|
-
import { _getComponent } from "../app/internal";
|
|
60
|
-
|
|
61
|
-
export { ErrorType, VerificationUsages, DeviceAuthorizeState } from "./consts";
|
|
62
|
-
export { ResponseError } from "../oauthclient";
|
|
50
|
+
import { getOAuthClient, Credentials, AuthClient, ResponseError, ErrorType as oauthErrorType } from '../oauthclient';
|
|
51
|
+
import { getCaptcha, Captcha } from '../captcha';
|
|
52
|
+
import { App, RequestFn as appRequestFn } from '../app';
|
|
53
|
+
import { _getComponent } from '../app/internal';
|
|
54
|
+
|
|
55
|
+
export { ErrorType, VerificationUsages, DeviceAuthorizeState } from './consts';
|
|
56
|
+
export { ResponseError } from '../oauthclient';
|
|
63
57
|
|
|
64
58
|
export interface AuthOptions {
|
|
65
59
|
credentialsClient: AuthClient;
|
|
@@ -70,19 +64,15 @@ export interface AuthOptions {
|
|
|
70
64
|
* Returns the existing `Auth` instance that is associated with the app
|
|
71
65
|
*/
|
|
72
66
|
export function getAuth(app: App, initOptions?: any): Auth {
|
|
73
|
-
return _getComponent<Auth>(
|
|
74
|
-
app,
|
|
75
|
-
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
captcha: captcha,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
);
|
|
67
|
+
return _getComponent<Auth>(app, 'auth', (): Auth => {
|
|
68
|
+
const credentialsClient = getOAuthClient(app, initOptions);
|
|
69
|
+
const baseRequest = credentialsClient.request.bind(credentialsClient);
|
|
70
|
+
const captcha = getCaptcha(app, { request: baseRequest });
|
|
71
|
+
return new Auth({
|
|
72
|
+
credentialsClient: credentialsClient,
|
|
73
|
+
captcha: captcha,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
86
76
|
}
|
|
87
77
|
|
|
88
78
|
export type GetCustomSignTicketFn = () => Promise<string>;
|
|
@@ -110,14 +100,11 @@ export class Auth {
|
|
|
110
100
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
111
101
|
*/
|
|
112
102
|
public async signIn(params: SignInRequest): Promise<Credentials> {
|
|
113
|
-
const credentials: Credentials = await this.request<Credentials>(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
body: params,
|
|
119
|
-
}
|
|
120
|
-
);
|
|
103
|
+
const credentials: Credentials = await this.request<Credentials>(ApiUrls.AUTH_SIGN_IN_URL, {
|
|
104
|
+
method: 'POST',
|
|
105
|
+
withBasicAuth: true,
|
|
106
|
+
body: params,
|
|
107
|
+
});
|
|
121
108
|
await this.credentialsClient.setCredentials(credentials);
|
|
122
109
|
return Promise.resolve(credentials);
|
|
123
110
|
}
|
|
@@ -127,14 +114,11 @@ export class Auth {
|
|
|
127
114
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
128
115
|
*/
|
|
129
116
|
public async signInAnonymously(): Promise<Credentials> {
|
|
130
|
-
const credentials: Credentials = await this.request<Credentials>(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
body: {},
|
|
136
|
-
}
|
|
137
|
-
);
|
|
117
|
+
const credentials: Credentials = await this.request<Credentials>(ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL, {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
withBasicAuth: true,
|
|
120
|
+
body: {},
|
|
121
|
+
});
|
|
138
122
|
await this.credentialsClient.setCredentials(credentials);
|
|
139
123
|
return Promise.resolve(credentials);
|
|
140
124
|
}
|
|
@@ -145,14 +129,11 @@ export class Auth {
|
|
|
145
129
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
146
130
|
*/
|
|
147
131
|
public async signUp(params: SignUpRequest): Promise<Credentials> {
|
|
148
|
-
const data: Credentials = await this.request<Credentials>(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
body: params,
|
|
154
|
-
}
|
|
155
|
-
);
|
|
132
|
+
const data: Credentials = await this.request<Credentials>(ApiUrls.AUTH_SIGN_UP_URL, {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
withBasicAuth: true,
|
|
135
|
+
body: params,
|
|
136
|
+
});
|
|
156
137
|
await this.credentialsClient.setCredentials(data);
|
|
157
138
|
return Promise.resolve(data);
|
|
158
139
|
}
|
|
@@ -165,17 +146,17 @@ export class Auth {
|
|
|
165
146
|
public async signOut(params?: SignoutRequest): Promise<SignoutReponse> {
|
|
166
147
|
var resp: SignoutReponse = {};
|
|
167
148
|
if (!params) {
|
|
168
|
-
params = {}
|
|
149
|
+
params = {};
|
|
169
150
|
}
|
|
170
151
|
try {
|
|
171
152
|
resp = await this.request<SignoutReponse>(ApiUrls.AUTH_SIGNOUT_URL, {
|
|
172
|
-
method:
|
|
153
|
+
method: 'POST',
|
|
173
154
|
withCredentials: true,
|
|
174
155
|
body: params,
|
|
175
156
|
});
|
|
176
157
|
} catch (err) {
|
|
177
158
|
if ((err as ResponseError).error !== oauthErrorType.UNAUTHENTICATED) {
|
|
178
|
-
console.log(
|
|
159
|
+
console.log('sign_out_error', err);
|
|
179
160
|
}
|
|
180
161
|
}
|
|
181
162
|
await this.credentialsClient.setCredentials();
|
|
@@ -188,7 +169,7 @@ export class Auth {
|
|
|
188
169
|
*/
|
|
189
170
|
public async revokeAllDevices(): Promise<void> {
|
|
190
171
|
await this.request<void>(ApiUrls.AUTH_REVOKE_ALL_URL, {
|
|
191
|
-
method:
|
|
172
|
+
method: 'DELETE',
|
|
192
173
|
withCredentials: true,
|
|
193
174
|
});
|
|
194
175
|
}
|
|
@@ -198,13 +179,10 @@ export class Auth {
|
|
|
198
179
|
* @return {Object} A Promise<void> object.
|
|
199
180
|
*/
|
|
200
181
|
public async revokeDevice(params: RevokeDeviceRequest): Promise<void> {
|
|
201
|
-
await this.request<void>(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
withCredentials: true,
|
|
206
|
-
}
|
|
207
|
-
);
|
|
182
|
+
await this.request<void>(ApiUrls.AUTHORIZED_DEVICES_DELETE_URL + params.device_id, {
|
|
183
|
+
method: 'DELETE',
|
|
184
|
+
withCredentials: true,
|
|
185
|
+
});
|
|
208
186
|
}
|
|
209
187
|
|
|
210
188
|
/**
|
|
@@ -212,13 +190,11 @@ export class Auth {
|
|
|
212
190
|
* @param {SendVerificationCodeRequest} params A GetVerificationRequest Object.
|
|
213
191
|
* @return {Promise<SendVerificationCodeResponse>} A Promise<GetVerificationResponse> object.
|
|
214
192
|
*/
|
|
215
|
-
public async sendVerificationCode(
|
|
216
|
-
params: SendVerificationCodeRequest
|
|
217
|
-
): Promise<SendVerificationCodeResponse> {
|
|
193
|
+
public async sendVerificationCode(params: SendVerificationCodeRequest): Promise<SendVerificationCodeResponse> {
|
|
218
194
|
let withBasicAuth = false;
|
|
219
195
|
let withCredentials = false;
|
|
220
196
|
// 发送短信时,如果时给当前用户发,则需要带上鉴权信息
|
|
221
|
-
if (params.target ==
|
|
197
|
+
if (params.target == 'CUR_USER') {
|
|
222
198
|
withCredentials = true;
|
|
223
199
|
} else {
|
|
224
200
|
const hasLogin = await this.hasLoginState();
|
|
@@ -228,16 +204,17 @@ export class Auth {
|
|
|
228
204
|
withBasicAuth = true;
|
|
229
205
|
}
|
|
230
206
|
}
|
|
231
|
-
return this.request<SendVerificationCodeResponse>(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
207
|
+
return this.request<SendVerificationCodeResponse>(ApiUrls.VERIFICATION_URL, {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
withBasicAuth: withBasicAuth,
|
|
210
|
+
withCredentials: withCredentials,
|
|
211
|
+
body: params,
|
|
212
|
+
withCaptcha: true,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public async getVerification(params: SendVerificationCodeRequest) {
|
|
217
|
+
return this.sendVerificationCode(params);
|
|
241
218
|
}
|
|
242
219
|
|
|
243
220
|
/**
|
|
@@ -247,7 +224,7 @@ export class Auth {
|
|
|
247
224
|
*/
|
|
248
225
|
public async verify(params: VerifyRequest): Promise<VerifyResponse> {
|
|
249
226
|
return this.request<VerifyResponse>(ApiUrls.VERIFY_URL, {
|
|
250
|
-
method:
|
|
227
|
+
method: 'POST',
|
|
251
228
|
withBasicAuth: true,
|
|
252
229
|
body: params,
|
|
253
230
|
});
|
|
@@ -259,7 +236,7 @@ export class Auth {
|
|
|
259
236
|
*/
|
|
260
237
|
public async resetPassword(params: ResetPasswordRequest): Promise<void> {
|
|
261
238
|
return this.request<void>(ApiUrls.RESET_PASSWORD_URL, {
|
|
262
|
-
method:
|
|
239
|
+
method: 'POST',
|
|
263
240
|
withBasicAuth: true,
|
|
264
241
|
body: params,
|
|
265
242
|
});
|
|
@@ -270,9 +247,7 @@ export class Auth {
|
|
|
270
247
|
* @param {GenProviderRedirectUriRequest} params A GenProviderRedirectUriRequest object.
|
|
271
248
|
* @return {Promise<GenProviderRedirectUriResponse>} A Promise<GenProviderRedirectUriResponse> object.
|
|
272
249
|
*/
|
|
273
|
-
public async genProviderRedirectUri(
|
|
274
|
-
params: GenProviderRedirectUriRequest
|
|
275
|
-
): Promise<GenProviderRedirectUriResponse> {
|
|
250
|
+
public async genProviderRedirectUri(params: GenProviderRedirectUriRequest): Promise<GenProviderRedirectUriResponse> {
|
|
276
251
|
const otherParams = params.other_params;
|
|
277
252
|
delete params.other_params;
|
|
278
253
|
let url = `${ApiUrls.PROVIDER_URI_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
@@ -282,7 +257,7 @@ export class Auth {
|
|
|
282
257
|
});
|
|
283
258
|
}
|
|
284
259
|
return this.request<GenProviderRedirectUriResponse>(url, {
|
|
285
|
-
method:
|
|
260
|
+
method: 'GET',
|
|
286
261
|
withBasicAuth: true,
|
|
287
262
|
});
|
|
288
263
|
}
|
|
@@ -292,17 +267,12 @@ export class Auth {
|
|
|
292
267
|
* @param {GrantProviderTokenRequest} params A GrantProviderTokenRequest object.
|
|
293
268
|
* @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
|
|
294
269
|
*/
|
|
295
|
-
public async grantProviderToken(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
method: "POST",
|
|
302
|
-
withBasicAuth: true,
|
|
303
|
-
body: params,
|
|
304
|
-
}
|
|
305
|
-
);
|
|
270
|
+
public async grantProviderToken(params: GrantProviderTokenRequest): Promise<GrantProviderTokenResponse> {
|
|
271
|
+
return this.request<GrantProviderTokenResponse>(ApiUrls.PROVIDER_TOKEN_URL, {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
withBasicAuth: true,
|
|
274
|
+
body: params,
|
|
275
|
+
});
|
|
306
276
|
}
|
|
307
277
|
|
|
308
278
|
/**
|
|
@@ -310,17 +280,12 @@ export class Auth {
|
|
|
310
280
|
* @param {PatchProviderTokenRequest} params A PatchProviderTokenRequest object.
|
|
311
281
|
* @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
|
|
312
282
|
*/
|
|
313
|
-
public async patchProviderToken(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
method: "PATCH",
|
|
320
|
-
withBasicAuth: true,
|
|
321
|
-
body: params,
|
|
322
|
-
}
|
|
323
|
-
);
|
|
283
|
+
public async patchProviderToken(params: PatchProviderTokenRequest): Promise<PatchProviderTokenResponse> {
|
|
284
|
+
return this.request<PatchProviderTokenResponse>(ApiUrls.PROVIDER_TOKEN_URL, {
|
|
285
|
+
method: 'PATCH',
|
|
286
|
+
withBasicAuth: true,
|
|
287
|
+
body: params,
|
|
288
|
+
});
|
|
324
289
|
}
|
|
325
290
|
|
|
326
291
|
/**
|
|
@@ -328,17 +293,12 @@ export class Auth {
|
|
|
328
293
|
* @param {SignInWithProviderRequest} params A SignInWithProviderRequest object.
|
|
329
294
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
330
295
|
*/
|
|
331
|
-
public async signInWithProvider(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
method: "POST",
|
|
338
|
-
withBasicAuth: true,
|
|
339
|
-
body: params,
|
|
340
|
-
}
|
|
341
|
-
);
|
|
296
|
+
public async signInWithProvider(params: SignInWithProviderRequest): Promise<Credentials> {
|
|
297
|
+
const credentials: Credentials = await this.request<Credentials>(ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL, {
|
|
298
|
+
method: 'POST',
|
|
299
|
+
withBasicAuth: true,
|
|
300
|
+
body: params,
|
|
301
|
+
});
|
|
342
302
|
await this.credentialsClient.setCredentials(credentials);
|
|
343
303
|
return Promise.resolve(credentials);
|
|
344
304
|
}
|
|
@@ -348,11 +308,9 @@ export class Auth {
|
|
|
348
308
|
* @param {BindWithProviderRequest} params A BindWithProviderRequest object.
|
|
349
309
|
* @return {Promise<void>} A Promise<void> object.
|
|
350
310
|
*/
|
|
351
|
-
public async bindWithProvider(
|
|
352
|
-
params: BindWithProviderRequest
|
|
353
|
-
): Promise<void> {
|
|
311
|
+
public async bindWithProvider(params: BindWithProviderRequest): Promise<void> {
|
|
354
312
|
return this.request<void>(ApiUrls.PROVIDER_BIND_URL, {
|
|
355
|
-
method:
|
|
313
|
+
method: 'POST',
|
|
356
314
|
withBasicAuth: true,
|
|
357
315
|
body: params,
|
|
358
316
|
withCredentials: true,
|
|
@@ -365,7 +323,7 @@ export class Auth {
|
|
|
365
323
|
*/
|
|
366
324
|
public async getUserProfile(): Promise<UserProfile> {
|
|
367
325
|
return this.request<UserProfile>(ApiUrls.USER_ME_URL, {
|
|
368
|
-
method:
|
|
326
|
+
method: 'GET',
|
|
369
327
|
withCredentials: true,
|
|
370
328
|
});
|
|
371
329
|
}
|
|
@@ -376,7 +334,7 @@ export class Auth {
|
|
|
376
334
|
*/
|
|
377
335
|
public async updateUserProfile(params: UserProfile): Promise<UserProfile> {
|
|
378
336
|
return this.request<UserProfile>(ApiUrls.USER_ME_URL, {
|
|
379
|
-
method:
|
|
337
|
+
method: 'PATCH',
|
|
380
338
|
withCredentials: true,
|
|
381
339
|
body: params,
|
|
382
340
|
});
|
|
@@ -411,11 +369,9 @@ export class Auth {
|
|
|
411
369
|
* @param {TransByProviderRequest} params A TransByProviderRequest object.
|
|
412
370
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
413
371
|
*/
|
|
414
|
-
public async transByProvider(
|
|
415
|
-
params: TransByProviderRequest
|
|
416
|
-
): Promise<Credentials> {
|
|
372
|
+
public async transByProvider(params: TransByProviderRequest): Promise<Credentials> {
|
|
417
373
|
return this.request<Credentials>(ApiUrls.USER_TRANS_BY_PROVIDER_URL, {
|
|
418
|
-
method:
|
|
374
|
+
method: 'PATCH',
|
|
419
375
|
body: params,
|
|
420
376
|
withCredentials: true,
|
|
421
377
|
});
|
|
@@ -427,14 +383,11 @@ export class Auth {
|
|
|
427
383
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
428
384
|
*/
|
|
429
385
|
public async grantToken(params: GrantTokenRequest): Promise<Credentials> {
|
|
430
|
-
const credentials: Credentials = await this.request<Credentials>(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
body: params,
|
|
436
|
-
}
|
|
437
|
-
);
|
|
386
|
+
const credentials: Credentials = await this.request<Credentials>(ApiUrls.AUTH_TOKEN_URL, {
|
|
387
|
+
method: 'POST',
|
|
388
|
+
withBasicAuth: true,
|
|
389
|
+
body: params,
|
|
390
|
+
});
|
|
438
391
|
await this.credentialsClient.setCredentials(credentials);
|
|
439
392
|
return Promise.resolve(credentials);
|
|
440
393
|
}
|
|
@@ -445,7 +398,7 @@ export class Auth {
|
|
|
445
398
|
*/
|
|
446
399
|
public async getProviders(): Promise<ProvidersResponse> {
|
|
447
400
|
return this.request<ProvidersResponse>(ApiUrls.PROVIDER_LIST_URL, {
|
|
448
|
-
method:
|
|
401
|
+
method: 'GET',
|
|
449
402
|
withCredentials: true,
|
|
450
403
|
});
|
|
451
404
|
}
|
|
@@ -454,12 +407,10 @@ export class Auth {
|
|
|
454
407
|
* check if username is exist
|
|
455
408
|
* @param params CheckIfUserExistRequest
|
|
456
409
|
*/
|
|
457
|
-
public async checkIfUserExist(
|
|
458
|
-
params: CheckIfUserExistRequest
|
|
459
|
-
): Promise<CheckIfUserExistResponse> {
|
|
410
|
+
public async checkIfUserExist(params: CheckIfUserExistRequest): Promise<CheckIfUserExistResponse> {
|
|
460
411
|
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
461
412
|
return this.request<CheckIfUserExistResponse>(url, {
|
|
462
|
-
method:
|
|
413
|
+
method: 'GET',
|
|
463
414
|
});
|
|
464
415
|
}
|
|
465
416
|
|
|
@@ -469,13 +420,10 @@ export class Auth {
|
|
|
469
420
|
* @return {Promise<void>}
|
|
470
421
|
*/
|
|
471
422
|
public async unbindProvider(params: UnbindProviderRequest): Promise<void> {
|
|
472
|
-
return this.request<void>(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
withCredentials: true,
|
|
477
|
-
}
|
|
478
|
-
);
|
|
423
|
+
return this.request<void>(`${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`, {
|
|
424
|
+
method: 'DELETE',
|
|
425
|
+
withCredentials: true,
|
|
426
|
+
});
|
|
479
427
|
}
|
|
480
428
|
|
|
481
429
|
/**
|
|
@@ -485,7 +433,7 @@ export class Auth {
|
|
|
485
433
|
*/
|
|
486
434
|
public async checkPassword(params: CheckPasswordRequest): Promise<void> {
|
|
487
435
|
return this.request<void>(`${ApiUrls.SUDO_URL}`, {
|
|
488
|
-
method:
|
|
436
|
+
method: 'POST',
|
|
489
437
|
withCredentials: true,
|
|
490
438
|
body: params,
|
|
491
439
|
});
|
|
@@ -498,7 +446,7 @@ export class Auth {
|
|
|
498
446
|
*/
|
|
499
447
|
public async editContact(params: EditContactRequest): Promise<void> {
|
|
500
448
|
return this.request<void>(`${ApiUrls.EDIT_CONTACT_URL}`, {
|
|
501
|
-
method:
|
|
449
|
+
method: 'PATCH',
|
|
502
450
|
withCredentials: true,
|
|
503
451
|
body: params,
|
|
504
452
|
});
|
|
@@ -511,7 +459,7 @@ export class Auth {
|
|
|
511
459
|
*/
|
|
512
460
|
public async setPassword(params: SetPasswordRequest): Promise<void> {
|
|
513
461
|
return this.request<void>(`${ApiUrls.AUTH_SET_PASSWORD_URL}`, {
|
|
514
|
-
method:
|
|
462
|
+
method: 'PATCH',
|
|
515
463
|
withCredentials: true,
|
|
516
464
|
body: params,
|
|
517
465
|
});
|
|
@@ -522,9 +470,7 @@ export class Auth {
|
|
|
522
470
|
* @param {UpdatePasswordRequest} params
|
|
523
471
|
* @return {Promise<void>}
|
|
524
472
|
*/
|
|
525
|
-
public async updatePasswordByOld(
|
|
526
|
-
params: UpdatePasswordRequest
|
|
527
|
-
): Promise<void> {
|
|
473
|
+
public async updatePasswordByOld(params: UpdatePasswordRequest): Promise<void> {
|
|
528
474
|
const sudoToken = await this.sudo({ password: params.old_password });
|
|
529
475
|
return this.setPassword({
|
|
530
476
|
sudo_token: sudoToken.sudo_token,
|
|
@@ -539,7 +485,7 @@ export class Auth {
|
|
|
539
485
|
*/
|
|
540
486
|
public async sudo(params: SudoRequest): Promise<SudoResponse> {
|
|
541
487
|
return this.request<SudoResponse>(`${ApiUrls.SUDO_URL}`, {
|
|
542
|
-
method:
|
|
488
|
+
method: 'POST',
|
|
543
489
|
withCredentials: true,
|
|
544
490
|
body: params,
|
|
545
491
|
});
|
|
@@ -551,18 +497,15 @@ export class Auth {
|
|
|
551
497
|
* @return {Promise<SendVerificationCodeResponse>} A Promise<SendVerificationCodeResponse> object.
|
|
552
498
|
*/
|
|
553
499
|
public async SendVerificationCodeToCurrentUser(
|
|
554
|
-
params: SendVerificationCodeRequest
|
|
500
|
+
params: SendVerificationCodeRequest,
|
|
555
501
|
): Promise<SendVerificationCodeResponse> {
|
|
556
|
-
params.target =
|
|
557
|
-
return this.request<SendVerificationCodeResponse>(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
withCaptcha: true,
|
|
564
|
-
}
|
|
565
|
-
);
|
|
502
|
+
params.target = 'CUR_USER';
|
|
503
|
+
return this.request<SendVerificationCodeResponse>(ApiUrls.VERIFICATION_URL, {
|
|
504
|
+
method: 'POST',
|
|
505
|
+
body: params,
|
|
506
|
+
withCredentials: true,
|
|
507
|
+
withCaptcha: true,
|
|
508
|
+
});
|
|
566
509
|
}
|
|
567
510
|
|
|
568
511
|
/**
|
|
@@ -570,19 +513,14 @@ export class Auth {
|
|
|
570
513
|
* @param {ChangeBoundProviderRequest} params A GetVerificationRequest Object.
|
|
571
514
|
* @return {Promise<ChangeBoundProviderResponse>} A Promise<GetVerificationResponse> object.
|
|
572
515
|
*/
|
|
573
|
-
public async changeBoundProvider(
|
|
574
|
-
params
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
provider_trans_token: params.trans_token,
|
|
582
|
-
},
|
|
583
|
-
withCredentials: true,
|
|
584
|
-
}
|
|
585
|
-
);
|
|
516
|
+
public async changeBoundProvider(params: ChangeBoundProviderRequest): Promise<ChangeBoundProviderResponse> {
|
|
517
|
+
return this.request<ChangeBoundProviderResponse>(`${ApiUrls.PROVIDER_LIST_URL}/${params.provider_id}/trans`, {
|
|
518
|
+
method: 'POST',
|
|
519
|
+
body: {
|
|
520
|
+
provider_trans_token: params.trans_token,
|
|
521
|
+
},
|
|
522
|
+
withCredentials: true,
|
|
523
|
+
});
|
|
586
524
|
}
|
|
587
525
|
|
|
588
526
|
/**
|
|
@@ -592,7 +530,7 @@ export class Auth {
|
|
|
592
530
|
*/
|
|
593
531
|
public async setUserProfile(params: UserProfile): Promise<UserProfile> {
|
|
594
532
|
return this.request<UserProfile>(ApiUrls.USER_PROFILE_URL, {
|
|
595
|
-
method:
|
|
533
|
+
method: 'PATCH',
|
|
596
534
|
body: params,
|
|
597
535
|
withCredentials: true,
|
|
598
536
|
});
|
|
@@ -605,7 +543,7 @@ export class Auth {
|
|
|
605
543
|
public async deleteMe(params: WithSudoRequest): Promise<UserProfile> {
|
|
606
544
|
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
607
545
|
return this.request<UserProfile>(url, {
|
|
608
|
-
method:
|
|
546
|
+
method: 'DELETE',
|
|
609
547
|
withCredentials: true,
|
|
610
548
|
});
|
|
611
549
|
}
|
|
@@ -626,14 +564,13 @@ export class Auth {
|
|
|
626
564
|
const customSignTicketFn = this._getCustomSignTicketFn;
|
|
627
565
|
if (!customSignTicketFn) {
|
|
628
566
|
return Promise.reject({
|
|
629
|
-
error:
|
|
630
|
-
error_description:
|
|
631
|
-
"please use setCustomSignFunc to set custom sign function",
|
|
567
|
+
error: 'failed_precondition',
|
|
568
|
+
error_description: 'please use setCustomSignFunc to set custom sign function',
|
|
632
569
|
});
|
|
633
570
|
}
|
|
634
571
|
const customTicket = await customSignTicketFn();
|
|
635
572
|
return this.signInWithProvider({
|
|
636
|
-
provider_id:
|
|
573
|
+
provider_id: 'custom',
|
|
637
574
|
provider_token: customTicket,
|
|
638
575
|
});
|
|
639
576
|
}
|
|
@@ -642,12 +579,10 @@ export class Auth {
|
|
|
642
579
|
* queryUserProfile query user profile
|
|
643
580
|
* @param params queryUserProfile query user profile
|
|
644
581
|
*/
|
|
645
|
-
public async queryUserProfile(
|
|
646
|
-
params: QueryUserProfileRequest
|
|
647
|
-
): Promise<QueryUserProfileResponse> {
|
|
582
|
+
public async queryUserProfile(params: QueryUserProfileRequest): Promise<QueryUserProfileResponse> {
|
|
648
583
|
const url = `${ApiUrls.USER_QUERY_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
649
584
|
return this.request<QueryUserProfileResponse>(url, {
|
|
650
|
-
method:
|
|
585
|
+
method: 'GET',
|
|
651
586
|
withCredentials: true,
|
|
652
587
|
});
|
|
653
588
|
}
|
|
@@ -659,7 +594,7 @@ export class Auth {
|
|
|
659
594
|
*/
|
|
660
595
|
public async authorize(params: AuthorizeRequest): Promise<AuthorizeResponse> {
|
|
661
596
|
return this.request<AuthorizeResponse>(ApiUrls.AUTHORIZE_URL, {
|
|
662
|
-
method:
|
|
597
|
+
method: 'POST',
|
|
663
598
|
withCredentials: true,
|
|
664
599
|
body: params,
|
|
665
600
|
});
|
|
@@ -671,23 +606,18 @@ export class Auth {
|
|
|
671
606
|
*/
|
|
672
607
|
public async authorizeDevice(params: AuthorizeDeviceRequest): Promise<void> {
|
|
673
608
|
return this.request<void>(ApiUrls.AUTHORIZE_DEVICE_URL, {
|
|
674
|
-
method:
|
|
609
|
+
method: 'POST',
|
|
675
610
|
withCredentials: true,
|
|
676
611
|
body: params,
|
|
677
612
|
});
|
|
678
613
|
}
|
|
679
614
|
|
|
680
|
-
public async deviceAuthorize(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
method: "POST",
|
|
687
|
-
withBasicAuth: true,
|
|
688
|
-
body: params,
|
|
689
|
-
}
|
|
690
|
-
);
|
|
615
|
+
public async deviceAuthorize(params: DeviceAuthorizeRequest): Promise<DeviceAuthorizeResponse> {
|
|
616
|
+
return this.request<DeviceAuthorizeResponse>(ApiUrls.AUTHORIZE_DEVICE_CODE_URL, {
|
|
617
|
+
method: 'POST',
|
|
618
|
+
withBasicAuth: true,
|
|
619
|
+
body: params,
|
|
620
|
+
});
|
|
691
621
|
}
|
|
692
622
|
|
|
693
623
|
/**
|
|
@@ -695,12 +625,8 @@ export class Auth {
|
|
|
695
625
|
* @param params
|
|
696
626
|
* @constructor
|
|
697
627
|
*/
|
|
698
|
-
public async authorizeInfo(
|
|
699
|
-
params
|
|
700
|
-
): Promise<AuthorizeInfoResponse> {
|
|
701
|
-
const url = `${ApiUrls.AUTHORIZE_INFO_URL}?${Auth.parseParamsToSearch(
|
|
702
|
-
params
|
|
703
|
-
)}`;
|
|
628
|
+
public async authorizeInfo(params: AuthorizeInfoRequest): Promise<AuthorizeInfoResponse> {
|
|
629
|
+
const url = `${ApiUrls.AUTHORIZE_INFO_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
704
630
|
let withBasicAuth = true;
|
|
705
631
|
let withCredentials = false;
|
|
706
632
|
const hasLogin = await this.hasLoginState();
|
|
@@ -709,7 +635,7 @@ export class Auth {
|
|
|
709
635
|
withBasicAuth = false;
|
|
710
636
|
}
|
|
711
637
|
return this.request<AuthorizeInfoResponse>(url, {
|
|
712
|
-
method:
|
|
638
|
+
method: 'GET',
|
|
713
639
|
withBasicAuth: withBasicAuth,
|
|
714
640
|
withCredentials: withCredentials,
|
|
715
641
|
});
|
|
@@ -725,7 +651,28 @@ export class Auth {
|
|
|
725
651
|
body: {
|
|
726
652
|
provider_id: 'weda',
|
|
727
653
|
},
|
|
728
|
-
})
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
public async createCaptchaData(params: { state: string; redirect_uri?: string }) {
|
|
658
|
+
return this.request<{ captcha_token: string; expires_in: number }>(ApiUrls.CAPTCHA_DATA_URL, {
|
|
659
|
+
method: 'POST',
|
|
660
|
+
withBasicAuth: true,
|
|
661
|
+
body: params,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* 验证输入验证码
|
|
667
|
+
* @param params.token 图形验证码token
|
|
668
|
+
* @param params.key 用户输入值
|
|
669
|
+
*/
|
|
670
|
+
public async verifyCaptchaData(params: { token: string; key: string }) {
|
|
671
|
+
return this.request<{ captcha_token: string; expires_in: number }>(ApiUrls.VERIFY_CAPTCHA_DATA_URL, {
|
|
672
|
+
method: 'POST',
|
|
673
|
+
withBasicAuth: true,
|
|
674
|
+
body: params,
|
|
675
|
+
});
|
|
729
676
|
}
|
|
730
677
|
|
|
731
678
|
private static parseParamsToSearch(params: any): string {
|