@cloudbase/oauth 2.4.5-beta.0 → 2.5.1-beta.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.
- package/.eslintrc.js +15 -0
- package/dist/cjs/auth/apis.d.ts +3 -3
- package/dist/cjs/auth/apis.js +69 -69
- package/dist/cjs/captcha/captcha.d.ts +9 -9
- package/dist/cjs/captcha/captcha.js +43 -46
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +6 -6
- package/dist/cjs/oauth2client/interface.d.ts +1 -1
- package/dist/cjs/oauth2client/interface.js +1 -1
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +31 -31
- package/dist/cjs/oauth2client/oauth2client.js +229 -229
- package/dist/cjs/utils/function/single-promise.d.ts +2 -2
- package/dist/cjs/utils/function/single-promise.js +40 -33
- package/dist/cjs/utils/uuid.js +2 -2
- package/dist/esm/auth/apis.d.ts +3 -3
- package/dist/esm/auth/apis.js +69 -69
- package/dist/esm/captcha/captcha.d.ts +9 -9
- package/dist/esm/captcha/captcha.js +44 -47
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +5 -5
- package/dist/esm/oauth2client/interface.d.ts +1 -1
- package/dist/esm/oauth2client/interface.js +1 -1
- package/dist/esm/oauth2client/models.js +1 -1
- package/dist/esm/oauth2client/oauth2client.d.ts +31 -31
- package/dist/esm/oauth2client/oauth2client.js +229 -229
- package/dist/esm/utils/function/single-promise.d.ts +2 -2
- package/dist/esm/utils/function/single-promise.js +40 -33
- package/dist/esm/utils/uuid.js +2 -2
- package/package.json +13 -6
- package/src/auth/apis.ts +135 -158
- package/src/captcha/captcha.ts +71 -78
- package/src/index.ts +13 -14
- package/src/oauth2client/interface.ts +5 -5
- package/src/oauth2client/models.ts +38 -38
- package/src/oauth2client/oauth2client.ts +255 -268
- package/src/utils/function/single-promise.ts +22 -21
- package/src/utils/uuid.ts +4 -4
- package/.eslintrc +0 -26
package/src/auth/apis.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
import { ApiUrls } from './consts'
|
|
3
|
+
import { ApiUrls } from './consts'
|
|
4
4
|
import {
|
|
5
5
|
GetVerificationRequest,
|
|
6
6
|
GetVerificationResponse,
|
|
@@ -40,12 +40,12 @@ import {
|
|
|
40
40
|
CheckUsernameRequest,
|
|
41
41
|
CheckIfUserExistRequest,
|
|
42
42
|
CheckIfUserExistResponse,
|
|
43
|
-
WithSudoRequest
|
|
44
|
-
} from './models'
|
|
45
|
-
import { SimpleStorage, RequestFunction } from '../oauth2client/interface'
|
|
46
|
-
import { OAuth2Client, defaultStorage } from '../oauth2client/oauth2client'
|
|
47
|
-
import { Credentials } from '../oauth2client/models'
|
|
48
|
-
import { Captcha } from '../captcha/captcha'
|
|
43
|
+
WithSudoRequest,
|
|
44
|
+
} from './models'
|
|
45
|
+
import { SimpleStorage, RequestFunction } from '../oauth2client/interface'
|
|
46
|
+
import { OAuth2Client, defaultStorage } from '../oauth2client/oauth2client'
|
|
47
|
+
import { Credentials } from '../oauth2client/models'
|
|
48
|
+
import { Captcha } from '../captcha/captcha'
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
export interface AuthOptions {
|
|
@@ -60,27 +60,36 @@ export interface AuthOptions {
|
|
|
60
60
|
* Auth
|
|
61
61
|
*/
|
|
62
62
|
export class Auth {
|
|
63
|
-
private
|
|
64
|
-
|
|
63
|
+
private static parseParamsToSearch(params: any): string {
|
|
64
|
+
Object.keys(params).forEach((key) => {
|
|
65
|
+
if (!params[key]) {
|
|
66
|
+
delete params[key]
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
const searchParams = new URLSearchParams(params as any)
|
|
70
|
+
return searchParams.toString()
|
|
71
|
+
}
|
|
65
72
|
|
|
73
|
+
private config: AuthOptions
|
|
74
|
+
private getCustomSignTicketFn?: GetCustomSignTicketFn
|
|
66
75
|
|
|
67
76
|
/**
|
|
68
77
|
* constructor
|
|
69
78
|
* @param {AuthOptions} opts
|
|
70
79
|
*/
|
|
71
80
|
constructor(opts: AuthOptions) {
|
|
72
|
-
let request = opts
|
|
73
|
-
let oAuth2Client = opts.credentialsClient
|
|
81
|
+
let { request } = opts
|
|
82
|
+
let oAuth2Client = opts.credentialsClient
|
|
74
83
|
if (!oAuth2Client) {
|
|
75
84
|
const initOptions = {
|
|
76
85
|
apiOrigin: opts.apiOrigin,
|
|
77
86
|
clientId: opts.clientId,
|
|
78
87
|
storage: opts.storage,
|
|
79
|
-
}
|
|
80
|
-
oAuth2Client = new OAuth2Client(initOptions)
|
|
88
|
+
}
|
|
89
|
+
oAuth2Client = new OAuth2Client(initOptions)
|
|
81
90
|
}
|
|
82
91
|
if (!request) {
|
|
83
|
-
const baseRequest = oAuth2Client.request.bind(oAuth2Client)
|
|
92
|
+
const baseRequest = oAuth2Client.request.bind(oAuth2Client)
|
|
84
93
|
const captcha = new Captcha({
|
|
85
94
|
clientId: opts.clientId,
|
|
86
95
|
request: baseRequest,
|
|
@@ -88,13 +97,13 @@ export class Auth {
|
|
|
88
97
|
})
|
|
89
98
|
request = captcha.request.bind(captcha)
|
|
90
99
|
}
|
|
91
|
-
this.
|
|
100
|
+
this.config = {
|
|
92
101
|
apiOrigin: opts.apiOrigin,
|
|
93
102
|
clientId: opts.clientId,
|
|
94
|
-
request
|
|
103
|
+
request,
|
|
95
104
|
credentialsClient: oAuth2Client,
|
|
96
105
|
storage: opts.storage || defaultStorage,
|
|
97
|
-
}
|
|
106
|
+
}
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
/**
|
|
@@ -103,15 +112,15 @@ export class Auth {
|
|
|
103
112
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
104
113
|
*/
|
|
105
114
|
public async signIn(params: SignInRequest): Promise<Credentials> {
|
|
106
|
-
const credentials: Credentials = await this.
|
|
115
|
+
const credentials: Credentials = await this.config.request<Credentials>(
|
|
107
116
|
ApiUrls.AUTH_SIGN_IN_URL,
|
|
108
117
|
{
|
|
109
118
|
method: 'POST',
|
|
110
|
-
body: params
|
|
119
|
+
body: params,
|
|
111
120
|
},
|
|
112
|
-
)
|
|
113
|
-
await this.
|
|
114
|
-
return Promise.resolve(credentials)
|
|
121
|
+
)
|
|
122
|
+
await this.config.credentialsClient.setCredentials(credentials)
|
|
123
|
+
return Promise.resolve(credentials)
|
|
115
124
|
}
|
|
116
125
|
|
|
117
126
|
/**
|
|
@@ -119,15 +128,15 @@ export class Auth {
|
|
|
119
128
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
120
129
|
*/
|
|
121
130
|
public async signInAnonymously(): Promise<Credentials> {
|
|
122
|
-
const credentials: Credentials = await this.
|
|
131
|
+
const credentials: Credentials = await this.config.request<Credentials>(
|
|
123
132
|
ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,
|
|
124
133
|
{
|
|
125
134
|
method: 'POST',
|
|
126
|
-
body: {}
|
|
135
|
+
body: {},
|
|
127
136
|
},
|
|
128
|
-
)
|
|
129
|
-
await this.
|
|
130
|
-
return Promise.resolve(credentials)
|
|
137
|
+
)
|
|
138
|
+
await this.config.credentialsClient.setCredentials(credentials)
|
|
139
|
+
return Promise.resolve(credentials)
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
/**
|
|
@@ -136,15 +145,15 @@ export class Auth {
|
|
|
136
145
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
137
146
|
*/
|
|
138
147
|
public async signUp(params: SignUpRequest): Promise<Credentials> {
|
|
139
|
-
const data: Credentials = await this.
|
|
148
|
+
const data: Credentials = await this.config.request<Credentials>(
|
|
140
149
|
ApiUrls.AUTH_SIGN_UP_URL,
|
|
141
150
|
{
|
|
142
151
|
method: 'POST',
|
|
143
152
|
body: params,
|
|
144
153
|
},
|
|
145
|
-
)
|
|
146
|
-
await this.
|
|
147
|
-
return Promise.resolve(data)
|
|
154
|
+
)
|
|
155
|
+
await this.config.credentialsClient.setCredentials(data)
|
|
156
|
+
return Promise.resolve(data)
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
/**
|
|
@@ -152,15 +161,15 @@ export class Auth {
|
|
|
152
161
|
* @return {Object} A Promise<void> object.
|
|
153
162
|
*/
|
|
154
163
|
public async signOut(): Promise<any> {
|
|
155
|
-
const accessToken: string = await this.
|
|
156
|
-
const data = await this.
|
|
164
|
+
const accessToken: string = await this.config.credentialsClient.getAccessToken()
|
|
165
|
+
const data = await this.config.request(ApiUrls.AUTH_REVOKE_URL, {
|
|
157
166
|
method: 'POST',
|
|
158
167
|
body: {
|
|
159
168
|
token: accessToken,
|
|
160
169
|
},
|
|
161
|
-
})
|
|
162
|
-
await this.
|
|
163
|
-
return Promise.resolve(data)
|
|
170
|
+
})
|
|
171
|
+
await this.config.credentialsClient.setCredentials()
|
|
172
|
+
return Promise.resolve(data)
|
|
164
173
|
}
|
|
165
174
|
|
|
166
175
|
/**
|
|
@@ -168,12 +177,10 @@ export class Auth {
|
|
|
168
177
|
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
169
178
|
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
170
179
|
*/
|
|
171
|
-
public async getVerification(
|
|
172
|
-
|
|
173
|
-
): Promise<GetVerificationResponse> {
|
|
174
|
-
let withCredentials = false;
|
|
180
|
+
public async getVerification(params: GetVerificationRequest,): Promise<GetVerificationResponse> {
|
|
181
|
+
let withCredentials = false
|
|
175
182
|
// 发送短信时,如果时给当前用户发,则需要带上鉴权信息
|
|
176
|
-
if (params.target
|
|
183
|
+
if (params.target === 'CUR_USER') {
|
|
177
184
|
withCredentials = true
|
|
178
185
|
} else {
|
|
179
186
|
const hasLogin = await this.hasLoginState()
|
|
@@ -181,15 +188,15 @@ export class Auth {
|
|
|
181
188
|
withCredentials = true
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
|
-
return this.
|
|
191
|
+
return this.config.request<GetVerificationResponse>(
|
|
185
192
|
ApiUrls.VERIFICATION_URL,
|
|
186
193
|
{
|
|
187
194
|
method: 'POST',
|
|
188
195
|
body: params,
|
|
189
196
|
withCaptcha: true,
|
|
190
|
-
withCredentials
|
|
197
|
+
withCredentials,
|
|
191
198
|
},
|
|
192
|
-
)
|
|
199
|
+
)
|
|
193
200
|
}
|
|
194
201
|
|
|
195
202
|
/**
|
|
@@ -198,10 +205,10 @@ export class Auth {
|
|
|
198
205
|
* @return {Promise<VerifyResponse>} A Promise<VerifyResponse> object.
|
|
199
206
|
*/
|
|
200
207
|
public async verify(params: VerifyRequest): Promise<VerifyResponse> {
|
|
201
|
-
return this.
|
|
208
|
+
return this.config.request<VerifyResponse>(ApiUrls.VERIFY_URL, {
|
|
202
209
|
method: 'POST',
|
|
203
210
|
body: params,
|
|
204
|
-
})
|
|
211
|
+
})
|
|
205
212
|
}
|
|
206
213
|
|
|
207
214
|
/**
|
|
@@ -209,25 +216,21 @@ export class Auth {
|
|
|
209
216
|
* @param {GenProviderRedirectUriRequest} params A GenProviderRedirectUriRequest object.
|
|
210
217
|
* @return {Promise<GenProviderRedirectUriResponse>} A Promise<GenProviderRedirectUriResponse> object.
|
|
211
218
|
*/
|
|
212
|
-
public async genProviderRedirectUri(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
params.provider_redirect_uri,
|
|
218
|
-
)}&state=${params.state}`;
|
|
219
|
-
const other_params = params.other_params;
|
|
220
|
-
if (other_params) {
|
|
219
|
+
public async genProviderRedirectUri(params: GenProviderRedirectUriRequest,): Promise<GenProviderRedirectUriResponse> {
|
|
220
|
+
let url = `${ApiUrls.PROVIDER_URI_URL}?client_id=${this.config.clientId
|
|
221
|
+
}&provider_id=${params.provider_id}&redirect_uri=${encodeURIComponent(params.provider_redirect_uri,)}&state=${params.state}`
|
|
222
|
+
const { other_params: otherParams } = params
|
|
223
|
+
if (otherParams) {
|
|
221
224
|
if (
|
|
222
|
-
typeof
|
|
223
|
-
|
|
225
|
+
typeof otherParams.sign_out_uri === 'string'
|
|
226
|
+
&& otherParams.sign_out_uri.length > 0
|
|
224
227
|
) {
|
|
225
|
-
url += `&other_params[sign_out_uri]=${
|
|
228
|
+
url += `&other_params[sign_out_uri]=${otherParams.sign_out_uri}`
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
|
-
return this.
|
|
231
|
+
return this.config.request<GenProviderRedirectUriResponse>(url, {
|
|
229
232
|
method: 'GET',
|
|
230
|
-
})
|
|
233
|
+
})
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
/**
|
|
@@ -235,16 +238,14 @@ export class Auth {
|
|
|
235
238
|
* @param {GrantProviderTokenRequest} params A GrantProviderTokenRequest object.
|
|
236
239
|
* @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
|
|
237
240
|
*/
|
|
238
|
-
public async grantProviderToken(
|
|
239
|
-
|
|
240
|
-
): Promise<GrantProviderTokenResponse> {
|
|
241
|
-
return this._config.request<GrantProviderTokenResponse>(
|
|
241
|
+
public async grantProviderToken(params: GrantProviderTokenRequest,): Promise<GrantProviderTokenResponse> {
|
|
242
|
+
return this.config.request<GrantProviderTokenResponse>(
|
|
242
243
|
ApiUrls.PROVIDER_TOKEN_URL,
|
|
243
244
|
{
|
|
244
245
|
method: 'POST',
|
|
245
246
|
body: params,
|
|
246
247
|
},
|
|
247
|
-
)
|
|
248
|
+
)
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
/**
|
|
@@ -252,16 +253,14 @@ export class Auth {
|
|
|
252
253
|
* @param {PatchProviderTokenRequest} params A PatchProviderTokenRequest object.
|
|
253
254
|
* @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
|
|
254
255
|
*/
|
|
255
|
-
public async patchProviderToken(
|
|
256
|
-
|
|
257
|
-
): Promise<PatchProviderTokenResponse> {
|
|
258
|
-
return this._config.request<PatchProviderTokenResponse>(
|
|
256
|
+
public async patchProviderToken(params: PatchProviderTokenRequest,): Promise<PatchProviderTokenResponse> {
|
|
257
|
+
return this.config.request<PatchProviderTokenResponse>(
|
|
259
258
|
ApiUrls.PROVIDER_TOKEN_URL,
|
|
260
259
|
{
|
|
261
260
|
method: 'PATCH',
|
|
262
261
|
body: params,
|
|
263
262
|
},
|
|
264
|
-
)
|
|
263
|
+
)
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
/**
|
|
@@ -269,18 +268,16 @@ export class Auth {
|
|
|
269
268
|
* @param {SignInWithProviderRequest} params A SignInWithProviderRequest object.
|
|
270
269
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
271
270
|
*/
|
|
272
|
-
public async signInWithProvider(
|
|
273
|
-
|
|
274
|
-
): Promise<Credentials> {
|
|
275
|
-
const credentials: Credentials = await this._config.request<Credentials>(
|
|
271
|
+
public async signInWithProvider(params: SignInWithProviderRequest,): Promise<Credentials> {
|
|
272
|
+
const credentials: Credentials = await this.config.request<Credentials>(
|
|
276
273
|
ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL,
|
|
277
274
|
{
|
|
278
275
|
method: 'POST',
|
|
279
276
|
body: params,
|
|
280
277
|
},
|
|
281
|
-
)
|
|
282
|
-
await this.
|
|
283
|
-
return Promise.resolve(credentials)
|
|
278
|
+
)
|
|
279
|
+
await this.config.credentialsClient.setCredentials(credentials)
|
|
280
|
+
return Promise.resolve(credentials)
|
|
284
281
|
}
|
|
285
282
|
|
|
286
283
|
/**
|
|
@@ -288,14 +285,12 @@ export class Auth {
|
|
|
288
285
|
* @param {BindWithProviderRequest} params A BindWithProviderRequest object.
|
|
289
286
|
* @return {Promise<void>} A Promise<any> object.
|
|
290
287
|
*/
|
|
291
|
-
public async bindWithProvider(
|
|
292
|
-
|
|
293
|
-
): Promise<void> {
|
|
294
|
-
return this._config.request<any>(ApiUrls.PROVIDER_BIND_URL, {
|
|
288
|
+
public async bindWithProvider(params: BindWithProviderRequest,): Promise<void> {
|
|
289
|
+
return this.config.request<any>(ApiUrls.PROVIDER_BIND_URL, {
|
|
295
290
|
method: 'POST',
|
|
296
291
|
body: params,
|
|
297
292
|
withCredentials: true,
|
|
298
|
-
})
|
|
293
|
+
})
|
|
299
294
|
}
|
|
300
295
|
|
|
301
296
|
/**
|
|
@@ -303,7 +298,7 @@ export class Auth {
|
|
|
303
298
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
304
299
|
*/
|
|
305
300
|
public async getUserProfile(): Promise<UserProfile> {
|
|
306
|
-
return this.getUserInfo()
|
|
301
|
+
return this.getUserInfo()
|
|
307
302
|
}
|
|
308
303
|
|
|
309
304
|
/**
|
|
@@ -311,16 +306,16 @@ export class Auth {
|
|
|
311
306
|
* @return {Promise<UserInfo>} A Promise<UserProfile> object.
|
|
312
307
|
*/
|
|
313
308
|
public async getUserInfo(): Promise<UserInfo> {
|
|
314
|
-
const userInfo = await this.
|
|
309
|
+
const userInfo = await this.config.request<UserInfo>(ApiUrls.USER_ME_URL, {
|
|
315
310
|
method: 'GET',
|
|
316
311
|
withCredentials: true,
|
|
317
|
-
})
|
|
312
|
+
})
|
|
318
313
|
|
|
319
314
|
if (userInfo.sub) {
|
|
320
315
|
userInfo.uid = userInfo.sub
|
|
321
316
|
}
|
|
322
317
|
|
|
323
|
-
return userInfo
|
|
318
|
+
return userInfo
|
|
324
319
|
}
|
|
325
320
|
|
|
326
321
|
/**
|
|
@@ -328,11 +323,11 @@ export class Auth {
|
|
|
328
323
|
* @param params
|
|
329
324
|
*/
|
|
330
325
|
public async deleteMe(params: WithSudoRequest): Promise<UserProfile> {
|
|
331
|
-
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}
|
|
332
|
-
return this.
|
|
326
|
+
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`
|
|
327
|
+
return this.config.request<UserProfile>(url, {
|
|
333
328
|
method: 'DELETE',
|
|
334
329
|
withCredentials: true,
|
|
335
|
-
})
|
|
330
|
+
})
|
|
336
331
|
}
|
|
337
332
|
|
|
338
333
|
/**
|
|
@@ -341,7 +336,7 @@ export class Auth {
|
|
|
341
336
|
*/
|
|
342
337
|
public async hasLoginState(): Promise<boolean> {
|
|
343
338
|
try {
|
|
344
|
-
await this.
|
|
339
|
+
await this.config.credentialsClient.getAccessToken()
|
|
345
340
|
return true
|
|
346
341
|
} catch (error) {
|
|
347
342
|
return false
|
|
@@ -349,12 +344,12 @@ export class Auth {
|
|
|
349
344
|
}
|
|
350
345
|
|
|
351
346
|
public hasLoginStateSync(): Credentials | null {
|
|
352
|
-
const credentials = this.
|
|
347
|
+
const credentials = this.config.credentialsClient.getCredentialsSync()
|
|
353
348
|
return credentials
|
|
354
349
|
}
|
|
355
350
|
|
|
356
351
|
public async getLoginState(): Promise<Credentials | null> {
|
|
357
|
-
return this.
|
|
352
|
+
return this.config.credentialsClient.getCredentialsAsync()
|
|
358
353
|
}
|
|
359
354
|
|
|
360
355
|
/**
|
|
@@ -362,17 +357,15 @@ export class Auth {
|
|
|
362
357
|
* @param {TransByProviderRequest} params A TransByProviderRequest object.
|
|
363
358
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
364
359
|
*/
|
|
365
|
-
public async transByProvider(
|
|
366
|
-
|
|
367
|
-
): Promise<Credentials> {
|
|
368
|
-
return this._config.request<Credentials>(
|
|
360
|
+
public async transByProvider(params: TransByProviderRequest,): Promise<Credentials> {
|
|
361
|
+
return this.config.request<Credentials>(
|
|
369
362
|
ApiUrls.USER_TRANS_BY_PROVIDER_URL,
|
|
370
363
|
{
|
|
371
364
|
method: 'PATCH',
|
|
372
365
|
body: params,
|
|
373
366
|
withCredentials: true,
|
|
374
367
|
},
|
|
375
|
-
)
|
|
368
|
+
)
|
|
376
369
|
}
|
|
377
370
|
|
|
378
371
|
/**
|
|
@@ -381,10 +374,10 @@ export class Auth {
|
|
|
381
374
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
382
375
|
*/
|
|
383
376
|
public async grantToken(params: GrantTokenRequest): Promise<Credentials> {
|
|
384
|
-
return this.
|
|
377
|
+
return this.config.request<Credentials>(ApiUrls.AUTH_TOKEN_URL, {
|
|
385
378
|
method: 'POST',
|
|
386
379
|
body: params,
|
|
387
|
-
})
|
|
380
|
+
})
|
|
388
381
|
}
|
|
389
382
|
|
|
390
383
|
/**
|
|
@@ -392,10 +385,10 @@ export class Auth {
|
|
|
392
385
|
* @return {Promise<UserProfileProvider>} A Promise<UserProfileProvider> object.
|
|
393
386
|
*/
|
|
394
387
|
public async getProviders(): Promise<UserProfileProvider> {
|
|
395
|
-
return this.
|
|
388
|
+
return this.config.request<UserProfileProvider>(ApiUrls.PROVIDER_LIST, {
|
|
396
389
|
method: 'GET',
|
|
397
390
|
withCredentials: true,
|
|
398
|
-
})
|
|
391
|
+
})
|
|
399
392
|
}
|
|
400
393
|
|
|
401
394
|
/**
|
|
@@ -404,13 +397,13 @@ export class Auth {
|
|
|
404
397
|
* @return {Promise<any>}
|
|
405
398
|
*/
|
|
406
399
|
public async unbindProvider(params: UnbindProviderRequest): Promise<void> {
|
|
407
|
-
return this.
|
|
400
|
+
return this.config.request<any>(
|
|
408
401
|
`${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`,
|
|
409
402
|
{
|
|
410
403
|
method: 'DELETE',
|
|
411
404
|
withCredentials: true,
|
|
412
405
|
},
|
|
413
|
-
)
|
|
406
|
+
)
|
|
414
407
|
}
|
|
415
408
|
|
|
416
409
|
/**
|
|
@@ -419,11 +412,11 @@ export class Auth {
|
|
|
419
412
|
* @return {Promise<any>}
|
|
420
413
|
*/
|
|
421
414
|
public async checkPassword(params: CheckPasswordrRequest): Promise<void> {
|
|
422
|
-
return this.
|
|
415
|
+
return this.config.request<any>(`${ApiUrls.CHECK_PWD_URL}`, {
|
|
423
416
|
method: 'POST',
|
|
424
417
|
withCredentials: true,
|
|
425
418
|
body: params,
|
|
426
|
-
})
|
|
419
|
+
})
|
|
427
420
|
}
|
|
428
421
|
|
|
429
422
|
/**
|
|
@@ -432,11 +425,11 @@ export class Auth {
|
|
|
432
425
|
* @return {Promise<any>}
|
|
433
426
|
*/
|
|
434
427
|
public async bindPhone(params: BindPhoneRequest): Promise<void> {
|
|
435
|
-
return this.
|
|
428
|
+
return this.config.request<any>(`${ApiUrls.BIND_CONTACT_URL}`, {
|
|
436
429
|
method: 'PATCH',
|
|
437
430
|
withCredentials: true,
|
|
438
431
|
body: params,
|
|
439
|
-
})
|
|
432
|
+
})
|
|
440
433
|
}
|
|
441
434
|
|
|
442
435
|
/**
|
|
@@ -445,11 +438,11 @@ export class Auth {
|
|
|
445
438
|
* @return {Promise<any>}
|
|
446
439
|
*/
|
|
447
440
|
public async bindEmail(params: BindEmailRequest): Promise<void> {
|
|
448
|
-
return this.
|
|
441
|
+
return this.config.request<any>(`${ApiUrls.BIND_CONTACT_URL}`, {
|
|
449
442
|
method: 'PATCH',
|
|
450
443
|
withCredentials: true,
|
|
451
444
|
body: params,
|
|
452
|
-
})
|
|
445
|
+
})
|
|
453
446
|
}
|
|
454
447
|
|
|
455
448
|
/**
|
|
@@ -458,11 +451,11 @@ export class Auth {
|
|
|
458
451
|
* @return {Promise<any>}
|
|
459
452
|
*/
|
|
460
453
|
public async setPassword(params: SetPasswordRequest): Promise<void> {
|
|
461
|
-
return this.
|
|
454
|
+
return this.config.request<any>(`${ApiUrls.AUTH_SET_PASSWORD}`, {
|
|
462
455
|
method: 'PATCH',
|
|
463
456
|
withCredentials: true,
|
|
464
457
|
body: params,
|
|
465
|
-
})
|
|
458
|
+
})
|
|
466
459
|
}
|
|
467
460
|
|
|
468
461
|
/**
|
|
@@ -485,11 +478,11 @@ export class Auth {
|
|
|
485
478
|
* @return {Promise<any>}
|
|
486
479
|
*/
|
|
487
480
|
public async sudo(params: SudoRequest): Promise<SudoResponse> {
|
|
488
|
-
return this.
|
|
481
|
+
return this.config.request<SudoResponse>(`${ApiUrls.SUDO_URL}`, {
|
|
489
482
|
method: 'POST',
|
|
490
483
|
withCredentials: true,
|
|
491
484
|
body: params,
|
|
492
|
-
})
|
|
485
|
+
})
|
|
493
486
|
}
|
|
494
487
|
|
|
495
488
|
/**
|
|
@@ -497,19 +490,17 @@ export class Auth {
|
|
|
497
490
|
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
498
491
|
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
499
492
|
*/
|
|
500
|
-
public async getCurUserVerification(
|
|
501
|
-
params
|
|
502
|
-
|
|
503
|
-
params.target = 'CUR_USER';
|
|
504
|
-
return this._config.request<GetVerificationResponse>(
|
|
493
|
+
public async getCurUserVerification(params: GetVerificationRequest,): Promise<GetVerificationResponse> {
|
|
494
|
+
params.target = 'CUR_USER'
|
|
495
|
+
return this.config.request<GetVerificationResponse>(
|
|
505
496
|
ApiUrls.VERIFICATION_URL,
|
|
506
497
|
{
|
|
507
498
|
method: 'POST',
|
|
508
499
|
body: params,
|
|
509
500
|
withCredentials: true,
|
|
510
|
-
withCaptcha: true
|
|
501
|
+
withCaptcha: true,
|
|
511
502
|
},
|
|
512
|
-
)
|
|
503
|
+
)
|
|
513
504
|
}
|
|
514
505
|
|
|
515
506
|
/**
|
|
@@ -517,10 +508,8 @@ export class Auth {
|
|
|
517
508
|
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
518
509
|
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
519
510
|
*/
|
|
520
|
-
public async changeBindedProvider(
|
|
521
|
-
|
|
522
|
-
): Promise<ChangeBindedProviderResponse> {
|
|
523
|
-
return this._config.request<ChangeBindedProviderResponse>(
|
|
511
|
+
public async changeBindedProvider(params: ChangeBindedProviderRequest,): Promise<ChangeBindedProviderResponse> {
|
|
512
|
+
return this.config.request<ChangeBindedProviderResponse>(
|
|
524
513
|
`${ApiUrls.PROVIDER_LIST}/${params.provider_id}/trans`,
|
|
525
514
|
{
|
|
526
515
|
method: 'POST',
|
|
@@ -529,7 +518,7 @@ export class Auth {
|
|
|
529
518
|
},
|
|
530
519
|
withCredentials: true,
|
|
531
520
|
},
|
|
532
|
-
)
|
|
521
|
+
)
|
|
533
522
|
}
|
|
534
523
|
|
|
535
524
|
/**
|
|
@@ -538,11 +527,11 @@ export class Auth {
|
|
|
538
527
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
539
528
|
*/
|
|
540
529
|
public async setUserProfile(params: UserProfile): Promise<UserProfile> {
|
|
541
|
-
return this.
|
|
530
|
+
return this.config.request<UserProfile>(ApiUrls.USER_PRIFILE_URL, {
|
|
542
531
|
method: 'PATCH',
|
|
543
532
|
body: params,
|
|
544
533
|
withCredentials: true,
|
|
545
|
-
})
|
|
534
|
+
})
|
|
546
535
|
}
|
|
547
536
|
|
|
548
537
|
/**
|
|
@@ -550,16 +539,14 @@ export class Auth {
|
|
|
550
539
|
* @param {QueryUserProfileReq} appended_params A QueryUserProfileReq Object.
|
|
551
540
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
552
541
|
*/
|
|
553
|
-
public async queryUserProfile(
|
|
554
|
-
params: QueryUserProfileRequest,
|
|
555
|
-
): Promise<QueryUserProfileResponse> {
|
|
542
|
+
public async queryUserProfile(params: QueryUserProfileRequest,): Promise<QueryUserProfileResponse> {
|
|
556
543
|
// let url = new URL(ApiUrls.USER_QUERY_URL);
|
|
557
|
-
const searchParams = new URLSearchParams(params as any)
|
|
544
|
+
const searchParams = new URLSearchParams(params as any)
|
|
558
545
|
// url.search = searchParams.toString();
|
|
559
|
-
return this.
|
|
546
|
+
return this.config.request<QueryUserProfileResponse>(`${ApiUrls.USER_QUERY_URL}?${searchParams.toString()}`, {
|
|
560
547
|
method: 'GET',
|
|
561
548
|
withCredentials: true,
|
|
562
|
-
})
|
|
549
|
+
})
|
|
563
550
|
}
|
|
564
551
|
|
|
565
552
|
/**
|
|
@@ -567,7 +554,7 @@ export class Auth {
|
|
|
567
554
|
* @param getTickFn
|
|
568
555
|
*/
|
|
569
556
|
public setCustomSignFunc(getTickFn: GetCustomSignTicketFn) {
|
|
570
|
-
this.
|
|
557
|
+
this.getCustomSignTicketFn = getTickFn
|
|
571
558
|
}
|
|
572
559
|
|
|
573
560
|
/**
|
|
@@ -575,10 +562,10 @@ export class Auth {
|
|
|
575
562
|
* @constructor
|
|
576
563
|
*/
|
|
577
564
|
public async signInWithCustomTicket(): Promise<Credentials> {
|
|
578
|
-
const customTicket = await this.
|
|
565
|
+
const customTicket = await this.getCustomSignTicketFn()
|
|
579
566
|
return this.signInWithProvider({
|
|
580
567
|
provider_id: 'custom',
|
|
581
|
-
provider_token: customTicket
|
|
568
|
+
provider_token: customTicket,
|
|
582
569
|
})
|
|
583
570
|
}
|
|
584
571
|
|
|
@@ -589,7 +576,7 @@ export class Auth {
|
|
|
589
576
|
* @memberof Auth
|
|
590
577
|
*/
|
|
591
578
|
public async resetPassword(params: ResetPasswordRequest): Promise<void> {
|
|
592
|
-
return this.
|
|
579
|
+
return this.config.request(ApiUrls.AUTH_RESET_PASSWORD, {
|
|
593
580
|
method: 'POST',
|
|
594
581
|
body: params,
|
|
595
582
|
// withCredentials: true
|
|
@@ -603,44 +590,34 @@ export class Auth {
|
|
|
603
590
|
* @memberof Auth
|
|
604
591
|
*/
|
|
605
592
|
public async deviceAuthorize(params: DeviceAuthorizeRequest): Promise<DeviceAuthorizeResponse> {
|
|
606
|
-
return this.
|
|
593
|
+
return this.config.request(ApiUrls.AUTH_GET_DEVICE_CODE, {
|
|
607
594
|
method: 'POST',
|
|
608
595
|
body: params,
|
|
609
|
-
withCredentials: true
|
|
596
|
+
withCredentials: true,
|
|
610
597
|
})
|
|
611
598
|
}
|
|
612
599
|
|
|
613
600
|
public async checkUsername(params: CheckUsernameRequest): Promise<void> {
|
|
614
|
-
return this.
|
|
601
|
+
return this.config.request(ApiUrls.CHECK_USERNAME, {
|
|
615
602
|
method: 'GET',
|
|
616
603
|
body: params,
|
|
617
|
-
withCredentials: true
|
|
604
|
+
withCredentials: true,
|
|
618
605
|
})
|
|
619
606
|
}
|
|
620
607
|
|
|
621
608
|
public async checkIfUserExist(params: CheckIfUserExistRequest): Promise<CheckIfUserExistResponse> {
|
|
622
|
-
const searchParams = new URLSearchParams(params as any)
|
|
609
|
+
const searchParams = new URLSearchParams(params as any)
|
|
623
610
|
|
|
624
|
-
return this.
|
|
625
|
-
method: 'GET'
|
|
626
|
-
})
|
|
611
|
+
return this.config.request<CheckIfUserExistResponse>(`${ApiUrls.CHECK_IF_USER_EXIST}?${searchParams.toString()}`, {
|
|
612
|
+
method: 'GET',
|
|
613
|
+
})
|
|
627
614
|
}
|
|
628
615
|
|
|
629
616
|
public async loginScope(): Promise<string> {
|
|
630
|
-
return this.
|
|
617
|
+
return this.config.credentialsClient.getScope()
|
|
631
618
|
}
|
|
632
619
|
|
|
633
620
|
public async loginGroups(): Promise<string[]> {
|
|
634
|
-
return this.
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
private static parseParamsToSearch(params: any): string {
|
|
638
|
-
for (let key in params) {
|
|
639
|
-
if (!params[key]) {
|
|
640
|
-
delete params[key]
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
const searchParams = new URLSearchParams(params as any);
|
|
644
|
-
return searchParams.toString();
|
|
621
|
+
return this.config.credentialsClient.getGroups()
|
|
645
622
|
}
|
|
646
623
|
}
|