@cloudbase/oauth 0.1.1-alpha.10 → 0.1.1-alpha.11
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.js +14 -9
- package/dist/app/internal.js +5 -1
- package/dist/app/openuri.js +7 -3
- package/dist/app/request.js +7 -3
- package/dist/app/storage.js +5 -1
- package/dist/auth/consts.js +11 -8
- package/dist/auth/index.js +56 -49
- package/dist/auth/models.js +2 -1
- package/dist/captcha/index.js +16 -11
- package/dist/function/index.js +14 -9
- package/dist/index.js +18 -9
- package/dist/oauthclient/consts.js +7 -4
- package/dist/oauthclient/index.js +11 -6
- package/dist/oauthclient/interface.js +5 -1
- package/dist/oauthclient/models.js +2 -1
- package/dist/oauthclient/oauthclient.js +27 -21
- package/dist/package.json +1 -1
- package/dist/utils/base64.js +13 -6
- package/dist/utils/mp.js +7 -2
- package/dist/utils/promise.js +5 -1
- package/dist/utils/uuid.js +5 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -2
package/dist/app/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppImpl = exports.initializeApp = void 0;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
const openuri_1 = require("./openuri");
|
|
6
|
+
const storage_1 = require("./storage");
|
|
7
|
+
function initializeApp(options) {
|
|
5
8
|
return new AppImpl(options);
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
exports.initializeApp = initializeApp;
|
|
11
|
+
class AppImpl {
|
|
8
12
|
constructor(options) {
|
|
9
13
|
this._container = new Map();
|
|
10
14
|
if (!options.region) {
|
|
@@ -21,18 +25,18 @@ export class AppImpl {
|
|
|
21
25
|
storageEnv = options.clientId;
|
|
22
26
|
}
|
|
23
27
|
if (!options.storage) {
|
|
24
|
-
options.storage = new DefaultStorage({ env: storageEnv });
|
|
28
|
+
options.storage = new storage_1.DefaultStorage({ env: storageEnv });
|
|
25
29
|
}
|
|
26
30
|
if (!options.captchaOptions) {
|
|
27
31
|
options.captchaOptions = {};
|
|
28
32
|
}
|
|
29
33
|
if (!options.captchaOptions.openURIWithCallback) {
|
|
30
34
|
// 兼容之前的传参方式,options.openURIWithCallback
|
|
31
|
-
options.captchaOptions.openURIWithCallback = options.openURIWithCallback || defaultOpenURIWithCallback;
|
|
35
|
+
options.captchaOptions.openURIWithCallback = options.openURIWithCallback || openuri_1.defaultOpenURIWithCallback;
|
|
32
36
|
}
|
|
33
|
-
let baseRequest = options.baseRequest || options.request || defaultRequest;
|
|
37
|
+
let baseRequest = options.baseRequest || options.request || request_1.defaultRequest;
|
|
34
38
|
if (!baseRequest) {
|
|
35
|
-
baseRequest = defaultRequest;
|
|
39
|
+
baseRequest = request_1.defaultRequest;
|
|
36
40
|
}
|
|
37
41
|
const apiOrigin = options.apiOrigin;
|
|
38
42
|
options.request = async (url, options) => {
|
|
@@ -50,3 +54,4 @@ export class AppImpl {
|
|
|
50
54
|
return this._container;
|
|
51
55
|
}
|
|
52
56
|
}
|
|
57
|
+
exports.AppImpl = AppImpl;
|
package/dist/app/internal.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._getComponent = void 0;
|
|
1
4
|
/**
|
|
2
5
|
*
|
|
3
6
|
* @param app - App instance
|
|
@@ -8,7 +11,7 @@
|
|
|
8
11
|
*
|
|
9
12
|
* @internal
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
function _getComponent(app, name, creator) {
|
|
12
15
|
const container = app.container;
|
|
13
16
|
let component = container.get(name);
|
|
14
17
|
if (component) {
|
|
@@ -18,3 +21,4 @@ export function _getComponent(app, name, creator) {
|
|
|
18
21
|
container.set(name, component);
|
|
19
22
|
return component;
|
|
20
23
|
}
|
|
24
|
+
exports._getComponent = _getComponent;
|
package/dist/app/openuri.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultOpenURIWithCallback = void 0;
|
|
4
|
+
const consts_1 = require("../auth/consts");
|
|
2
5
|
/**
|
|
3
6
|
* default use iframe to open url can return callback
|
|
4
7
|
* for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/
|
|
@@ -11,13 +14,13 @@ import { ErrorType } from '../auth/consts';
|
|
|
11
14
|
}, false);
|
|
12
15
|
*
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
const defaultOpenURIWithCallback = (url, opts) => {
|
|
15
18
|
let iframeTag = '__iframe';
|
|
16
19
|
const { width = '355px', height = '355px' } = opts || {};
|
|
17
20
|
const matched = url.match(/^(data:.*)$/);
|
|
18
21
|
if (matched) {
|
|
19
22
|
return Promise.reject({
|
|
20
|
-
error: ErrorType.UNIMPLEMENTED,
|
|
23
|
+
error: consts_1.ErrorType.UNIMPLEMENTED,
|
|
21
24
|
error_description: `need to impl captcha data`,
|
|
22
25
|
});
|
|
23
26
|
}
|
|
@@ -105,5 +108,6 @@ export const defaultOpenURIWithCallback = (url, opts) => {
|
|
|
105
108
|
};
|
|
106
109
|
});
|
|
107
110
|
};
|
|
111
|
+
exports.defaultOpenURIWithCallback = defaultOpenURIWithCallback;
|
|
108
112
|
class Callback {
|
|
109
113
|
}
|
package/dist/app/request.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultRequest = exports.ErrorType = void 0;
|
|
4
|
+
var ErrorType;
|
|
2
5
|
(function (ErrorType) {
|
|
3
6
|
ErrorType["UNREACHABLE"] = "unreachable";
|
|
4
|
-
})(ErrorType || (ErrorType = {}));
|
|
5
|
-
|
|
7
|
+
})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
|
|
8
|
+
const defaultRequest = async (url, options) => {
|
|
6
9
|
let result;
|
|
7
10
|
let responseError;
|
|
8
11
|
// Objects must be copied to prevent modification of data such as body.
|
|
@@ -51,3 +54,4 @@ export const defaultRequest = async (url, options) => {
|
|
|
51
54
|
return result;
|
|
52
55
|
}
|
|
53
56
|
};
|
|
57
|
+
exports.defaultRequest = defaultRequest;
|
package/dist/app/storage.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultStorage = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Default Storage.
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
class DefaultStorage {
|
|
5
8
|
constructor(opts) {
|
|
6
9
|
this._env = opts.env;
|
|
7
10
|
}
|
|
@@ -28,3 +31,4 @@ export class DefaultStorage {
|
|
|
28
31
|
return localStorage.setItem(key + this._env, value);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
34
|
+
exports.DefaultStorage = DefaultStorage;
|
package/dist/auth/consts.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceAuthorizeState = exports.ErrorType = exports.VerificationUsages = exports.ApiUrls = void 0;
|
|
4
|
+
var ApiUrls;
|
|
2
5
|
(function (ApiUrls) {
|
|
3
6
|
ApiUrls["AUTH_SIGN_IN_URL"] = "/auth/v1/signin";
|
|
4
7
|
ApiUrls["AUTH_SIGN_IN_ANONYMOUSLY_URL"] = "/auth/v1/signin/anonymously";
|
|
@@ -36,16 +39,16 @@ export var ApiUrls;
|
|
|
36
39
|
ApiUrls["AUTHORIZED_DEVICES_DELETE_URL"] = "/auth/v1/user/authorized/devices/";
|
|
37
40
|
ApiUrls["AUTH_REVOKE_ALL_URL"] = "/auth/v1/user/revoke/all";
|
|
38
41
|
ApiUrls["GET_PROVIDER_TYPE"] = "/auth/v1/mgr/provider/providerSubType";
|
|
39
|
-
})(ApiUrls || (ApiUrls = {}));
|
|
40
|
-
|
|
42
|
+
})(ApiUrls = exports.ApiUrls || (exports.ApiUrls = {}));
|
|
43
|
+
var VerificationUsages;
|
|
41
44
|
(function (VerificationUsages) {
|
|
42
45
|
VerificationUsages["REGISTER"] = "REGISTER";
|
|
43
46
|
VerificationUsages["SIGN_IN"] = "SIGN_IN";
|
|
44
47
|
VerificationUsages["PASSWORD_RESET"] = "PASSWORD_RESET";
|
|
45
48
|
VerificationUsages["EMAIL_ADDRESS_CHANGE"] = "EMAIL_ADDRESS_CHANGE";
|
|
46
49
|
VerificationUsages["PHONE_NUMBER_CHANGE"] = "PHONE_NUMBER_CHANGE";
|
|
47
|
-
})(VerificationUsages || (VerificationUsages = {}));
|
|
48
|
-
|
|
50
|
+
})(VerificationUsages = exports.VerificationUsages || (exports.VerificationUsages = {}));
|
|
51
|
+
var ErrorType;
|
|
49
52
|
(function (ErrorType) {
|
|
50
53
|
ErrorType["INVALID_ARGUMENT"] = "invalid_argument";
|
|
51
54
|
ErrorType["DEADLINE_EXCEEDED"] = "deadline_exceeded";
|
|
@@ -66,8 +69,8 @@ export var ErrorType;
|
|
|
66
69
|
ErrorType["INVALID_STATUS"] = "invalid_status";
|
|
67
70
|
ErrorType["USER_PENDING"] = "user_pending";
|
|
68
71
|
ErrorType["USER_BLOCKED"] = "user_blocked";
|
|
69
|
-
})(ErrorType || (ErrorType = {}));
|
|
70
|
-
|
|
72
|
+
})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
|
|
73
|
+
var DeviceAuthorizeState;
|
|
71
74
|
(function (DeviceAuthorizeState) {
|
|
72
75
|
// 完成
|
|
73
76
|
DeviceAuthorizeState["ACCOMPLISHED"] = "ACCOMPLISHED";
|
|
@@ -77,4 +80,4 @@ export var DeviceAuthorizeState;
|
|
|
77
80
|
DeviceAuthorizeState["WAITING_CONSENT"] = "WAITING_CONSENT";
|
|
78
81
|
// 用户拒绝授权
|
|
79
82
|
DeviceAuthorizeState["ACCESS_DENIED"] = "ACCESS_DENIED";
|
|
80
|
-
})(DeviceAuthorizeState || (DeviceAuthorizeState = {}));
|
|
83
|
+
})(DeviceAuthorizeState = exports.DeviceAuthorizeState || (exports.DeviceAuthorizeState = {}));
|
package/dist/auth/index.js
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth = exports.getAuth = exports.DeviceAuthorizeState = exports.VerificationUsages = exports.ErrorType = void 0;
|
|
4
|
+
const consts_1 = require("./consts");
|
|
5
|
+
const oauthclient_1 = require("../oauthclient");
|
|
6
|
+
const captcha_1 = require("../captcha");
|
|
7
|
+
const internal_1 = require("../app/internal");
|
|
8
|
+
var consts_2 = require("./consts");
|
|
9
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return consts_2.ErrorType; } });
|
|
10
|
+
Object.defineProperty(exports, "VerificationUsages", { enumerable: true, get: function () { return consts_2.VerificationUsages; } });
|
|
11
|
+
Object.defineProperty(exports, "DeviceAuthorizeState", { enumerable: true, get: function () { return consts_2.DeviceAuthorizeState; } });
|
|
7
12
|
/**
|
|
8
13
|
* Returns the existing `Auth` instance that is associated with the app
|
|
9
14
|
*/
|
|
10
|
-
|
|
11
|
-
return _getComponent(app, 'auth', () => {
|
|
12
|
-
const credentialsClient = getOAuthClient(app, initOptions);
|
|
15
|
+
function getAuth(app, initOptions) {
|
|
16
|
+
return (0, internal_1._getComponent)(app, 'auth', () => {
|
|
17
|
+
const credentialsClient = (0, oauthclient_1.getOAuthClient)(app, initOptions);
|
|
13
18
|
const baseRequest = credentialsClient.request.bind(credentialsClient);
|
|
14
|
-
const captcha = getCaptcha(app, { request: baseRequest });
|
|
19
|
+
const captcha = (0, captcha_1.getCaptcha)(app, { request: baseRequest });
|
|
15
20
|
return new Auth({
|
|
16
21
|
credentialsClient: credentialsClient,
|
|
17
22
|
captcha: captcha,
|
|
18
23
|
});
|
|
19
24
|
});
|
|
20
25
|
}
|
|
26
|
+
exports.getAuth = getAuth;
|
|
21
27
|
/**
|
|
22
28
|
* Auth
|
|
23
29
|
*/
|
|
24
|
-
|
|
30
|
+
class Auth {
|
|
25
31
|
/**
|
|
26
32
|
* constructor
|
|
27
33
|
* @param {AuthOptions} opts
|
|
@@ -36,7 +42,7 @@ export class Auth {
|
|
|
36
42
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
37
43
|
*/
|
|
38
44
|
async signIn(params) {
|
|
39
|
-
const credentials = await this.request(ApiUrls.AUTH_SIGN_IN_URL, {
|
|
45
|
+
const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_URL, {
|
|
40
46
|
method: 'POST',
|
|
41
47
|
withBasicAuth: true,
|
|
42
48
|
body: params,
|
|
@@ -49,7 +55,7 @@ export class Auth {
|
|
|
49
55
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
50
56
|
*/
|
|
51
57
|
async signInAnonymously() {
|
|
52
|
-
const credentials = await this.request(ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL, {
|
|
58
|
+
const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL, {
|
|
53
59
|
method: 'POST',
|
|
54
60
|
withBasicAuth: true,
|
|
55
61
|
body: {},
|
|
@@ -63,7 +69,7 @@ export class Auth {
|
|
|
63
69
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
64
70
|
*/
|
|
65
71
|
async signUp(params) {
|
|
66
|
-
const data = await this.request(ApiUrls.AUTH_SIGN_UP_URL, {
|
|
72
|
+
const data = await this.request(consts_1.ApiUrls.AUTH_SIGN_UP_URL, {
|
|
67
73
|
method: 'POST',
|
|
68
74
|
withBasicAuth: true,
|
|
69
75
|
body: params,
|
|
@@ -82,14 +88,14 @@ export class Auth {
|
|
|
82
88
|
params = {};
|
|
83
89
|
}
|
|
84
90
|
try {
|
|
85
|
-
resp = await this.request(ApiUrls.AUTH_SIGNOUT_URL, {
|
|
91
|
+
resp = await this.request(consts_1.ApiUrls.AUTH_SIGNOUT_URL, {
|
|
86
92
|
method: 'POST',
|
|
87
93
|
withCredentials: true,
|
|
88
94
|
body: params,
|
|
89
95
|
});
|
|
90
96
|
}
|
|
91
97
|
catch (err) {
|
|
92
|
-
if (err.error !==
|
|
98
|
+
if (err.error !== oauthclient_1.ErrorType.UNAUTHENTICATED) {
|
|
93
99
|
console.log('sign_out_error', err);
|
|
94
100
|
}
|
|
95
101
|
}
|
|
@@ -101,7 +107,7 @@ export class Auth {
|
|
|
101
107
|
* @return {Object} A Promise<void> object.
|
|
102
108
|
*/
|
|
103
109
|
async revokeAllDevices() {
|
|
104
|
-
await this.request(ApiUrls.AUTH_REVOKE_ALL_URL, {
|
|
110
|
+
await this.request(consts_1.ApiUrls.AUTH_REVOKE_ALL_URL, {
|
|
105
111
|
method: 'DELETE',
|
|
106
112
|
withCredentials: true,
|
|
107
113
|
});
|
|
@@ -111,7 +117,7 @@ export class Auth {
|
|
|
111
117
|
* @return {Object} A Promise<void> object.
|
|
112
118
|
*/
|
|
113
119
|
async revokeDevice(params) {
|
|
114
|
-
await this.request(ApiUrls.AUTHORIZED_DEVICES_DELETE_URL + params.device_id, {
|
|
120
|
+
await this.request(consts_1.ApiUrls.AUTHORIZED_DEVICES_DELETE_URL + params.device_id, {
|
|
115
121
|
method: 'DELETE',
|
|
116
122
|
withCredentials: true,
|
|
117
123
|
});
|
|
@@ -137,7 +143,7 @@ export class Auth {
|
|
|
137
143
|
withBasicAuth = true;
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
|
-
return this.request(ApiUrls.VERIFICATION_URL, {
|
|
146
|
+
return this.request(consts_1.ApiUrls.VERIFICATION_URL, {
|
|
141
147
|
method: 'POST',
|
|
142
148
|
withBasicAuth: withBasicAuth,
|
|
143
149
|
withCredentials: withCredentials,
|
|
@@ -154,7 +160,7 @@ export class Auth {
|
|
|
154
160
|
* @return {Promise<VerifyResponse>} A Promise<VerifyResponse> object.
|
|
155
161
|
*/
|
|
156
162
|
async verify(params) {
|
|
157
|
-
return this.request(ApiUrls.VERIFY_URL, {
|
|
163
|
+
return this.request(consts_1.ApiUrls.VERIFY_URL, {
|
|
158
164
|
method: 'POST',
|
|
159
165
|
withBasicAuth: true,
|
|
160
166
|
body: params,
|
|
@@ -165,7 +171,7 @@ export class Auth {
|
|
|
165
171
|
* @param params A ResetPasswordRequest Object
|
|
166
172
|
*/
|
|
167
173
|
async resetPassword(params) {
|
|
168
|
-
return this.request(ApiUrls.RESET_PASSWORD_URL, {
|
|
174
|
+
return this.request(consts_1.ApiUrls.RESET_PASSWORD_URL, {
|
|
169
175
|
method: 'POST',
|
|
170
176
|
withBasicAuth: true,
|
|
171
177
|
body: params,
|
|
@@ -179,7 +185,7 @@ export class Auth {
|
|
|
179
185
|
async genProviderRedirectUri(params) {
|
|
180
186
|
const otherParams = params.other_params;
|
|
181
187
|
delete params.other_params;
|
|
182
|
-
let url = `${ApiUrls.PROVIDER_URI_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
188
|
+
let url = `${consts_1.ApiUrls.PROVIDER_URI_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
183
189
|
if (otherParams) {
|
|
184
190
|
otherParams.forEach((value, key) => {
|
|
185
191
|
url += `&other_params[${key}]=${encodeURIComponent(value)}`;
|
|
@@ -196,7 +202,7 @@ export class Auth {
|
|
|
196
202
|
* @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
|
|
197
203
|
*/
|
|
198
204
|
async grantProviderToken(params) {
|
|
199
|
-
return this.request(ApiUrls.PROVIDER_TOKEN_URL, {
|
|
205
|
+
return this.request(consts_1.ApiUrls.PROVIDER_TOKEN_URL, {
|
|
200
206
|
method: 'POST',
|
|
201
207
|
withBasicAuth: true,
|
|
202
208
|
body: params,
|
|
@@ -208,7 +214,7 @@ export class Auth {
|
|
|
208
214
|
* @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
|
|
209
215
|
*/
|
|
210
216
|
async patchProviderToken(params) {
|
|
211
|
-
return this.request(ApiUrls.PROVIDER_TOKEN_URL, {
|
|
217
|
+
return this.request(consts_1.ApiUrls.PROVIDER_TOKEN_URL, {
|
|
212
218
|
method: 'PATCH',
|
|
213
219
|
withBasicAuth: true,
|
|
214
220
|
body: params,
|
|
@@ -220,7 +226,7 @@ export class Auth {
|
|
|
220
226
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
221
227
|
*/
|
|
222
228
|
async signInWithProvider(params) {
|
|
223
|
-
const credentials = await this.request(ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL, {
|
|
229
|
+
const credentials = await this.request(consts_1.ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL, {
|
|
224
230
|
method: 'POST',
|
|
225
231
|
withBasicAuth: true,
|
|
226
232
|
body: params,
|
|
@@ -234,7 +240,7 @@ export class Auth {
|
|
|
234
240
|
* @return {Promise<void>} A Promise<void> object.
|
|
235
241
|
*/
|
|
236
242
|
async bindWithProvider(params) {
|
|
237
|
-
return this.request(ApiUrls.PROVIDER_BIND_URL, {
|
|
243
|
+
return this.request(consts_1.ApiUrls.PROVIDER_BIND_URL, {
|
|
238
244
|
method: 'POST',
|
|
239
245
|
withBasicAuth: true,
|
|
240
246
|
body: params,
|
|
@@ -246,7 +252,7 @@ export class Auth {
|
|
|
246
252
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
247
253
|
*/
|
|
248
254
|
async getUserProfile() {
|
|
249
|
-
return this.request(ApiUrls.USER_ME_URL, {
|
|
255
|
+
return this.request(consts_1.ApiUrls.USER_ME_URL, {
|
|
250
256
|
method: 'GET',
|
|
251
257
|
withCredentials: true,
|
|
252
258
|
});
|
|
@@ -256,7 +262,7 @@ export class Auth {
|
|
|
256
262
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
257
263
|
*/
|
|
258
264
|
async updateUserProfile(params) {
|
|
259
|
-
return this.request(ApiUrls.USER_ME_URL, {
|
|
265
|
+
return this.request(consts_1.ApiUrls.USER_ME_URL, {
|
|
260
266
|
method: 'PATCH',
|
|
261
267
|
withCredentials: true,
|
|
262
268
|
body: params,
|
|
@@ -272,7 +278,7 @@ export class Auth {
|
|
|
272
278
|
return true;
|
|
273
279
|
}
|
|
274
280
|
catch (err) {
|
|
275
|
-
if (err.error ===
|
|
281
|
+
if (err.error === oauthclient_1.ErrorType.UNAUTHENTICATED) {
|
|
276
282
|
return false;
|
|
277
283
|
}
|
|
278
284
|
return Promise.reject(err);
|
|
@@ -291,7 +297,7 @@ export class Auth {
|
|
|
291
297
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
292
298
|
*/
|
|
293
299
|
async transByProvider(params) {
|
|
294
|
-
return this.request(ApiUrls.USER_TRANS_BY_PROVIDER_URL, {
|
|
300
|
+
return this.request(consts_1.ApiUrls.USER_TRANS_BY_PROVIDER_URL, {
|
|
295
301
|
method: 'PATCH',
|
|
296
302
|
body: params,
|
|
297
303
|
withCredentials: true,
|
|
@@ -303,7 +309,7 @@ export class Auth {
|
|
|
303
309
|
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
304
310
|
*/
|
|
305
311
|
async grantToken(params) {
|
|
306
|
-
const credentials = await this.request(ApiUrls.AUTH_TOKEN_URL, {
|
|
312
|
+
const credentials = await this.request(consts_1.ApiUrls.AUTH_TOKEN_URL, {
|
|
307
313
|
method: 'POST',
|
|
308
314
|
withBasicAuth: true,
|
|
309
315
|
body: params,
|
|
@@ -316,7 +322,7 @@ export class Auth {
|
|
|
316
322
|
* @return {Promise<ProvidersResponse>} A Promise<UserProfileProviderList> object.
|
|
317
323
|
*/
|
|
318
324
|
async getProviders() {
|
|
319
|
-
return this.request(ApiUrls.PROVIDER_LIST_URL, {
|
|
325
|
+
return this.request(consts_1.ApiUrls.PROVIDER_LIST_URL, {
|
|
320
326
|
method: 'GET',
|
|
321
327
|
withCredentials: true,
|
|
322
328
|
});
|
|
@@ -326,7 +332,7 @@ export class Auth {
|
|
|
326
332
|
* @param params CheckIfUserExistRequest
|
|
327
333
|
*/
|
|
328
334
|
async checkIfUserExist(params) {
|
|
329
|
-
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
335
|
+
const url = `${consts_1.ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
330
336
|
return this.request(url, {
|
|
331
337
|
method: 'GET',
|
|
332
338
|
});
|
|
@@ -337,7 +343,7 @@ export class Auth {
|
|
|
337
343
|
* @return {Promise<void>}
|
|
338
344
|
*/
|
|
339
345
|
async unbindProvider(params) {
|
|
340
|
-
return this.request(`${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`, {
|
|
346
|
+
return this.request(`${consts_1.ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`, {
|
|
341
347
|
method: 'DELETE',
|
|
342
348
|
withCredentials: true,
|
|
343
349
|
});
|
|
@@ -348,7 +354,7 @@ export class Auth {
|
|
|
348
354
|
* @return {Promise<void>}
|
|
349
355
|
*/
|
|
350
356
|
async checkPassword(params) {
|
|
351
|
-
return this.request(`${ApiUrls.SUDO_URL}`, {
|
|
357
|
+
return this.request(`${consts_1.ApiUrls.SUDO_URL}`, {
|
|
352
358
|
method: 'POST',
|
|
353
359
|
withCredentials: true,
|
|
354
360
|
body: params,
|
|
@@ -360,7 +366,7 @@ export class Auth {
|
|
|
360
366
|
* @return {Promise<void>}
|
|
361
367
|
*/
|
|
362
368
|
async editContact(params) {
|
|
363
|
-
return this.request(`${ApiUrls.EDIT_CONTACT_URL}`, {
|
|
369
|
+
return this.request(`${consts_1.ApiUrls.EDIT_CONTACT_URL}`, {
|
|
364
370
|
method: 'PATCH',
|
|
365
371
|
withCredentials: true,
|
|
366
372
|
body: params,
|
|
@@ -372,7 +378,7 @@ export class Auth {
|
|
|
372
378
|
* @return {Promise<void>}
|
|
373
379
|
*/
|
|
374
380
|
async setPassword(params) {
|
|
375
|
-
return this.request(`${ApiUrls.AUTH_SET_PASSWORD_URL}`, {
|
|
381
|
+
return this.request(`${consts_1.ApiUrls.AUTH_SET_PASSWORD_URL}`, {
|
|
376
382
|
method: 'PATCH',
|
|
377
383
|
withCredentials: true,
|
|
378
384
|
body: params,
|
|
@@ -396,7 +402,7 @@ export class Auth {
|
|
|
396
402
|
* @return {Promise<SudoResponse>}
|
|
397
403
|
*/
|
|
398
404
|
async sudo(params) {
|
|
399
|
-
return this.request(`${ApiUrls.SUDO_URL}`, {
|
|
405
|
+
return this.request(`${consts_1.ApiUrls.SUDO_URL}`, {
|
|
400
406
|
method: 'POST',
|
|
401
407
|
withCredentials: true,
|
|
402
408
|
body: params,
|
|
@@ -409,7 +415,7 @@ export class Auth {
|
|
|
409
415
|
*/
|
|
410
416
|
async SendVerificationCodeToCurrentUser(params) {
|
|
411
417
|
params.target = 'CUR_USER';
|
|
412
|
-
return this.request(ApiUrls.VERIFICATION_URL, {
|
|
418
|
+
return this.request(consts_1.ApiUrls.VERIFICATION_URL, {
|
|
413
419
|
method: 'POST',
|
|
414
420
|
body: params,
|
|
415
421
|
withCredentials: true,
|
|
@@ -422,7 +428,7 @@ export class Auth {
|
|
|
422
428
|
* @return {Promise<ChangeBoundProviderResponse>} A Promise<GetVerificationResponse> object.
|
|
423
429
|
*/
|
|
424
430
|
async changeBoundProvider(params) {
|
|
425
|
-
return this.request(`${ApiUrls.PROVIDER_LIST_URL}/${params.provider_id}/trans`, {
|
|
431
|
+
return this.request(`${consts_1.ApiUrls.PROVIDER_LIST_URL}/${params.provider_id}/trans`, {
|
|
426
432
|
method: 'POST',
|
|
427
433
|
body: {
|
|
428
434
|
provider_trans_token: params.trans_token,
|
|
@@ -436,7 +442,7 @@ export class Auth {
|
|
|
436
442
|
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
437
443
|
*/
|
|
438
444
|
async setUserProfile(params) {
|
|
439
|
-
return this.request(ApiUrls.USER_PROFILE_URL, {
|
|
445
|
+
return this.request(consts_1.ApiUrls.USER_PROFILE_URL, {
|
|
440
446
|
method: 'PATCH',
|
|
441
447
|
body: params,
|
|
442
448
|
withCredentials: true,
|
|
@@ -447,7 +453,7 @@ export class Auth {
|
|
|
447
453
|
* @param params
|
|
448
454
|
*/
|
|
449
455
|
async deleteMe(params) {
|
|
450
|
-
const url = `${ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
456
|
+
const url = `${consts_1.ApiUrls.USER_ME_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
451
457
|
return this.request(url, {
|
|
452
458
|
method: 'DELETE',
|
|
453
459
|
withCredentials: true,
|
|
@@ -483,7 +489,7 @@ export class Auth {
|
|
|
483
489
|
* @param params queryUserProfile query user profile
|
|
484
490
|
*/
|
|
485
491
|
async queryUserProfile(params) {
|
|
486
|
-
const url = `${ApiUrls.USER_QUERY_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
492
|
+
const url = `${consts_1.ApiUrls.USER_QUERY_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
487
493
|
return this.request(url, {
|
|
488
494
|
method: 'GET',
|
|
489
495
|
withCredentials: true,
|
|
@@ -495,7 +501,7 @@ export class Auth {
|
|
|
495
501
|
* @constructor
|
|
496
502
|
*/
|
|
497
503
|
async authorize(params) {
|
|
498
|
-
return this.request(ApiUrls.AUTHORIZE_URL, {
|
|
504
|
+
return this.request(consts_1.ApiUrls.AUTHORIZE_URL, {
|
|
499
505
|
method: 'POST',
|
|
500
506
|
withCredentials: true,
|
|
501
507
|
body: params,
|
|
@@ -506,14 +512,14 @@ export class Auth {
|
|
|
506
512
|
* @param params
|
|
507
513
|
*/
|
|
508
514
|
async authorizeDevice(params) {
|
|
509
|
-
return this.request(ApiUrls.AUTHORIZE_DEVICE_URL, {
|
|
515
|
+
return this.request(consts_1.ApiUrls.AUTHORIZE_DEVICE_URL, {
|
|
510
516
|
method: 'POST',
|
|
511
517
|
withCredentials: true,
|
|
512
518
|
body: params,
|
|
513
519
|
});
|
|
514
520
|
}
|
|
515
521
|
async deviceAuthorize(params) {
|
|
516
|
-
return this.request(ApiUrls.AUTHORIZE_DEVICE_CODE_URL, {
|
|
522
|
+
return this.request(consts_1.ApiUrls.AUTHORIZE_DEVICE_CODE_URL, {
|
|
517
523
|
method: 'POST',
|
|
518
524
|
withBasicAuth: true,
|
|
519
525
|
body: params,
|
|
@@ -525,7 +531,7 @@ export class Auth {
|
|
|
525
531
|
* @constructor
|
|
526
532
|
*/
|
|
527
533
|
async authorizeInfo(params) {
|
|
528
|
-
const url = `${ApiUrls.AUTHORIZE_INFO_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
534
|
+
const url = `${consts_1.ApiUrls.AUTHORIZE_INFO_URL}?${Auth.parseParamsToSearch(params)}`;
|
|
529
535
|
let withBasicAuth = true;
|
|
530
536
|
let withCredentials = false;
|
|
531
537
|
const hasLogin = await this.hasLoginState();
|
|
@@ -544,7 +550,7 @@ export class Auth {
|
|
|
544
550
|
* @returns
|
|
545
551
|
*/
|
|
546
552
|
async getProviderSubType() {
|
|
547
|
-
return this.request(ApiUrls.GET_PROVIDER_TYPE, {
|
|
553
|
+
return this.request(consts_1.ApiUrls.GET_PROVIDER_TYPE, {
|
|
548
554
|
method: 'POST',
|
|
549
555
|
body: {
|
|
550
556
|
provider_id: 'weda',
|
|
@@ -552,7 +558,7 @@ export class Auth {
|
|
|
552
558
|
});
|
|
553
559
|
}
|
|
554
560
|
async createCaptchaData(params) {
|
|
555
|
-
return this.request(ApiUrls.CAPTCHA_DATA_URL, {
|
|
561
|
+
return this.request(consts_1.ApiUrls.CAPTCHA_DATA_URL, {
|
|
556
562
|
method: 'POST',
|
|
557
563
|
withBasicAuth: true,
|
|
558
564
|
body: params,
|
|
@@ -564,7 +570,7 @@ export class Auth {
|
|
|
564
570
|
* @param params.key 用户输入值
|
|
565
571
|
*/
|
|
566
572
|
async verifyCaptchaData(params) {
|
|
567
|
-
return this.request(ApiUrls.VERIFY_CAPTCHA_DATA_URL, {
|
|
573
|
+
return this.request(consts_1.ApiUrls.VERIFY_CAPTCHA_DATA_URL, {
|
|
568
574
|
method: 'POST',
|
|
569
575
|
withBasicAuth: true,
|
|
570
576
|
body: params,
|
|
@@ -580,3 +586,4 @@ export class Auth {
|
|
|
580
586
|
return searchParams.toString();
|
|
581
587
|
}
|
|
582
588
|
}
|
|
589
|
+
exports.Auth = Auth;
|
package/dist/auth/models.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/captcha/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Captcha = exports.getCaptcha = void 0;
|
|
4
|
+
const consts_1 = require("../auth/consts");
|
|
5
|
+
const internal_1 = require("../app/internal");
|
|
6
|
+
const mp_1 = require("../utils/mp");
|
|
7
|
+
function getCaptcha(app, opts) {
|
|
8
|
+
return (0, internal_1._getComponent)(app, 'captcha', () => {
|
|
6
9
|
const initOpts = {
|
|
7
10
|
...app.options.captchaOptions,
|
|
8
11
|
clientId: app.options.clientId,
|
|
@@ -15,7 +18,8 @@ export function getCaptcha(app, opts) {
|
|
|
15
18
|
return new Captcha(initOpts);
|
|
16
19
|
});
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
exports.getCaptcha = getCaptcha;
|
|
22
|
+
class Captcha {
|
|
19
23
|
/**
|
|
20
24
|
* constructor
|
|
21
25
|
* @param {CaptchaOptions} opts
|
|
@@ -46,8 +50,8 @@ export class Captcha {
|
|
|
46
50
|
resp = await this.config.request(reqURL, options);
|
|
47
51
|
}
|
|
48
52
|
catch (err) {
|
|
49
|
-
if (err.error === ErrorType.CAPTCHA_REQUIRED || err.error === ErrorType.CAPTCHA_INVALID) {
|
|
50
|
-
url = await this.appendCaptchaTokenToURL(url, state, err.error === ErrorType.CAPTCHA_INVALID);
|
|
53
|
+
if (err.error === consts_1.ErrorType.CAPTCHA_REQUIRED || err.error === consts_1.ErrorType.CAPTCHA_INVALID) {
|
|
54
|
+
url = await this.appendCaptchaTokenToURL(url, state, err.error === consts_1.ErrorType.CAPTCHA_INVALID);
|
|
51
55
|
return this.config.request(url, options);
|
|
52
56
|
}
|
|
53
57
|
return Promise.reject(err);
|
|
@@ -66,11 +70,11 @@ export class Captcha {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
let captchaTokenResp;
|
|
69
|
-
if (isMp() || isInMpWebView()) {
|
|
73
|
+
if ((0, mp_1.isMp)() || (0, mp_1.isInMpWebView)()) {
|
|
70
74
|
/**
|
|
71
75
|
* https://iwiki.woa.com/p/4010699417
|
|
72
76
|
*/
|
|
73
|
-
const captchaDataResp = await this.config.request(ApiUrls.CAPTCHA_DATA_URL, {
|
|
77
|
+
const captchaDataResp = await this.config.request(consts_1.ApiUrls.CAPTCHA_DATA_URL, {
|
|
74
78
|
method: 'POST',
|
|
75
79
|
body: {
|
|
76
80
|
state,
|
|
@@ -85,7 +89,7 @@ export class Captcha {
|
|
|
85
89
|
}
|
|
86
90
|
else {
|
|
87
91
|
const redirect_uri = `${window.location.origin + window.location.pathname}?__captcha=on`;
|
|
88
|
-
captchaTokenResp = await this.config.request(ApiUrls.GET_CAPTCHA_URL, {
|
|
92
|
+
captchaTokenResp = await this.config.request(consts_1.ApiUrls.GET_CAPTCHA_URL, {
|
|
89
93
|
method: 'POST',
|
|
90
94
|
body: {
|
|
91
95
|
client_id: this.config.clientId,
|
|
@@ -147,3 +151,4 @@ export class Captcha {
|
|
|
147
151
|
return null;
|
|
148
152
|
}
|
|
149
153
|
}
|
|
154
|
+
exports.Captcha = Captcha;
|
package/dist/function/index.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Function = exports.getFunction = void 0;
|
|
4
|
+
const oauthclient_1 = require("../oauthclient");
|
|
5
|
+
const uuid_1 = require("../utils/uuid");
|
|
6
|
+
const internal_1 = require("../app/internal");
|
|
4
7
|
/**
|
|
5
8
|
* Returns the existing `Auth` instance that is associated with the app
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return _getComponent(app, "function", () => {
|
|
9
|
-
const credentialsClient = getOAuthClient(app);
|
|
10
|
+
function getFunction(app) {
|
|
11
|
+
return (0, internal_1._getComponent)(app, "function", () => {
|
|
12
|
+
const credentialsClient = (0, oauthclient_1.getOAuthClient)(app);
|
|
10
13
|
return new Function({
|
|
11
14
|
credentialsClient: credentialsClient,
|
|
12
15
|
env: app.options.clientId
|
|
13
16
|
});
|
|
14
17
|
});
|
|
15
18
|
}
|
|
16
|
-
|
|
19
|
+
exports.getFunction = getFunction;
|
|
20
|
+
class Function {
|
|
17
21
|
/**
|
|
18
22
|
* constructor
|
|
19
23
|
* @param {AuthOptions} opts
|
|
@@ -35,14 +39,14 @@ export class Function {
|
|
|
35
39
|
accessToken = await this._config.credentialsClient.getAccessToken();
|
|
36
40
|
}
|
|
37
41
|
catch (e) {
|
|
38
|
-
if (e.error === ErrorType.UNAUTHENTICATED) {
|
|
42
|
+
if (e.error === oauthclient_1.ErrorType.UNAUTHENTICATED) {
|
|
39
43
|
accessToken = "";
|
|
40
44
|
}
|
|
41
45
|
else {
|
|
42
46
|
return Promise.reject(e);
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
|
-
const requestId = uuidv4();
|
|
49
|
+
const requestId = (0, uuid_1.uuidv4)();
|
|
46
50
|
var reqBody = {
|
|
47
51
|
"action": "functions.invokeFunction",
|
|
48
52
|
"dataVersion": "2020-01-10",
|
|
@@ -72,3 +76,4 @@ export class Function {
|
|
|
72
76
|
};
|
|
73
77
|
}
|
|
74
78
|
}
|
|
79
|
+
exports.Function = Function;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuth = exports.Auth = exports.initializeApp = exports.ErrorType = exports.Client = exports.initializeClient = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const app_1 = require("./app");
|
|
6
|
+
function initializeClient(options) {
|
|
4
7
|
return new Client(options);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
exports.initializeClient = initializeClient;
|
|
10
|
+
class Client {
|
|
7
11
|
constructor(initOptions) {
|
|
8
|
-
this.app = initializeApp(initOptions);
|
|
9
|
-
this.auth = getAuth(this.app);
|
|
12
|
+
this.app = (0, app_1.initializeApp)(initOptions);
|
|
13
|
+
this.auth = (0, auth_1.getAuth)(this.app);
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
exports.Client = Client;
|
|
17
|
+
var request_1 = require("./app/request");
|
|
18
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return request_1.ErrorType; } });
|
|
19
|
+
var app_2 = require("./app");
|
|
20
|
+
Object.defineProperty(exports, "initializeApp", { enumerable: true, get: function () { return app_2.initializeApp; } });
|
|
21
|
+
var auth_2 = require("./auth");
|
|
22
|
+
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return auth_2.Auth; } });
|
|
23
|
+
Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return auth_2.getAuth; } });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorType = exports.Syntax = void 0;
|
|
4
|
+
var Syntax;
|
|
2
5
|
(function (Syntax) {
|
|
3
6
|
Syntax["CLIENT_ID"] = "client_id";
|
|
4
7
|
Syntax["CLIENT_SECRET"] = "client_secret";
|
|
@@ -17,8 +20,8 @@ export var Syntax;
|
|
|
17
20
|
Syntax["USERNAME"] = "username";
|
|
18
21
|
Syntax["PASSWORD"] = "password";
|
|
19
22
|
Syntax["REFRESH_TOKEN"] = "refresh_token";
|
|
20
|
-
})(Syntax || (Syntax = {}));
|
|
21
|
-
|
|
23
|
+
})(Syntax = exports.Syntax || (exports.Syntax = {}));
|
|
24
|
+
var ErrorType;
|
|
22
25
|
(function (ErrorType) {
|
|
23
26
|
ErrorType["UNREACHABLE"] = "unreachable";
|
|
24
27
|
ErrorType["LOCAL"] = "local";
|
|
@@ -46,4 +49,4 @@ export var ErrorType;
|
|
|
46
49
|
ErrorType["SERVER_ERROR"] = "server_error";
|
|
47
50
|
ErrorType["TEMPORARILY_UNAVAILABLE"] = "temporarily_unavailable";
|
|
48
51
|
ErrorType["INTERACTION_REQUIRED"] = "interaction_required";
|
|
49
|
-
})(ErrorType || (ErrorType = {}));
|
|
52
|
+
})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOAuthClient = exports.ErrorType = void 0;
|
|
4
|
+
const internal_1 = require("../app/internal");
|
|
5
|
+
const oauthclient_1 = require("./oauthclient");
|
|
6
|
+
var consts_1 = require("./consts");
|
|
7
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return consts_1.ErrorType; } });
|
|
8
|
+
function getOAuthClient(app, opts) {
|
|
9
|
+
return (0, internal_1._getComponent)(app, "oauthclient", () => {
|
|
6
10
|
const appOpts = app.options;
|
|
7
11
|
const oauthOpts = {
|
|
8
12
|
clientId: appOpts.clientId,
|
|
@@ -10,6 +14,7 @@ export function getOAuthClient(app, opts) {
|
|
|
10
14
|
request: appOpts.request,
|
|
11
15
|
storage: appOpts.storage,
|
|
12
16
|
};
|
|
13
|
-
return (new OAuth2Client(oauthOpts));
|
|
17
|
+
return (new oauthclient_1.OAuth2Client(oauthOpts));
|
|
14
18
|
});
|
|
15
19
|
}
|
|
20
|
+
exports.getOAuthClient = getOAuthClient;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuth2Client = exports.LocalCredentials = exports.generateRequestId = exports.toResponseError = void 0;
|
|
4
|
+
const consts_1 = require("./consts");
|
|
5
|
+
const uuid_1 = require("../utils/uuid");
|
|
6
|
+
const base64_1 = require("../utils/base64");
|
|
7
|
+
const promise_1 = require("../utils/promise");
|
|
5
8
|
const RequestIdHeaderName = 'x-request-id';
|
|
6
9
|
const DeviceIdHeaderName = 'x-device-id';
|
|
7
10
|
const DeviceIdSectionName = 'device_';
|
|
8
|
-
|
|
11
|
+
const toResponseError = (error, options) => {
|
|
9
12
|
let responseError;
|
|
10
13
|
const formatOptions = options || {};
|
|
11
14
|
if (error instanceof Error) {
|
|
12
15
|
responseError = {
|
|
13
|
-
error: formatOptions.error || ErrorType.LOCAL,
|
|
16
|
+
error: formatOptions.error || consts_1.ErrorType.LOCAL,
|
|
14
17
|
error_description: formatOptions.error_description || error.message,
|
|
15
18
|
error_uri: formatOptions.error_uri,
|
|
16
19
|
details: formatOptions.details || error.stack,
|
|
@@ -19,7 +22,7 @@ export const toResponseError = (error, options) => {
|
|
|
19
22
|
else {
|
|
20
23
|
const formatError = error || {};
|
|
21
24
|
responseError = {
|
|
22
|
-
error: formatOptions.error || formatError.error || ErrorType.LOCAL,
|
|
25
|
+
error: formatOptions.error || formatError.error || consts_1.ErrorType.LOCAL,
|
|
23
26
|
error_description: formatOptions.error_description || formatError.error_description,
|
|
24
27
|
error_uri: formatOptions.error_uri || formatError.error_uri,
|
|
25
28
|
details: formatOptions.details || formatError.details,
|
|
@@ -27,13 +30,15 @@ export const toResponseError = (error, options) => {
|
|
|
27
30
|
}
|
|
28
31
|
return responseError;
|
|
29
32
|
};
|
|
33
|
+
exports.toResponseError = toResponseError;
|
|
30
34
|
/**
|
|
31
35
|
* Generate request id.
|
|
32
36
|
* @return {string}
|
|
33
37
|
*/
|
|
34
|
-
|
|
35
|
-
return uuidv4();
|
|
38
|
+
function generateRequestId() {
|
|
39
|
+
return (0, uuid_1.uuidv4)();
|
|
36
40
|
}
|
|
41
|
+
exports.generateRequestId = generateRequestId;
|
|
37
42
|
/**
|
|
38
43
|
* Check if credentials is expired.
|
|
39
44
|
* @param {Credentials} credentials
|
|
@@ -51,14 +56,14 @@ function isCredentialsExpired(credentials) {
|
|
|
51
56
|
* Local credentials, with memory cache and storage cache.
|
|
52
57
|
* If the memory cache expires, the storage cache is automatically loaded.
|
|
53
58
|
*/
|
|
54
|
-
|
|
59
|
+
class LocalCredentials {
|
|
55
60
|
/**
|
|
56
61
|
* constructor
|
|
57
62
|
* @param {LocalCredentialsOptions} options
|
|
58
63
|
*/
|
|
59
64
|
constructor(options) {
|
|
60
65
|
this._credentials = null;
|
|
61
|
-
this._promiseOnce = new PromiseOnce();
|
|
66
|
+
this._promiseOnce = new promise_1.PromiseOnce();
|
|
62
67
|
this._tokenSectionName = options.tokenSectionName;
|
|
63
68
|
this._storage = options.storage;
|
|
64
69
|
}
|
|
@@ -117,6 +122,7 @@ export class LocalCredentials {
|
|
|
117
122
|
});
|
|
118
123
|
}
|
|
119
124
|
}
|
|
125
|
+
exports.LocalCredentials = LocalCredentials;
|
|
120
126
|
/**
|
|
121
127
|
* OAuth2Client
|
|
122
128
|
*/
|
|
@@ -126,14 +132,14 @@ class OAuth2Client {
|
|
|
126
132
|
* @param {OAuth2ClientOptions} options
|
|
127
133
|
*/
|
|
128
134
|
constructor(options) {
|
|
129
|
-
this._promiseOnce = new PromiseOnce();
|
|
135
|
+
this._promiseOnce = new promise_1.PromiseOnce();
|
|
130
136
|
this._retry = this._formatRetry(options.retry, OAuth2Client._defaultRetry);
|
|
131
137
|
this._baseRequest = options.request;
|
|
132
138
|
if (!options.clientSecret) {
|
|
133
139
|
options.clientSecret = "";
|
|
134
140
|
}
|
|
135
141
|
if (options.clientId !== '') {
|
|
136
|
-
this._basicAuth = "Basic " + weBtoa(options.clientId + ":" + options.clientSecret);
|
|
142
|
+
this._basicAuth = "Basic " + (0, base64_1.weBtoa)(options.clientId + ":" + options.clientSecret);
|
|
137
143
|
}
|
|
138
144
|
this._tokenInURL = options.tokenInURL;
|
|
139
145
|
this._headers = options.headers;
|
|
@@ -162,7 +168,7 @@ class OAuth2Client {
|
|
|
162
168
|
if (credentials && credentials.access_token) {
|
|
163
169
|
return Promise.resolve(credentials.access_token);
|
|
164
170
|
}
|
|
165
|
-
return Promise.reject({ error: ErrorType.UNAUTHENTICATED });
|
|
171
|
+
return Promise.reject({ error: consts_1.ErrorType.UNAUTHENTICATED });
|
|
166
172
|
}
|
|
167
173
|
/**
|
|
168
174
|
* getScope return a validate access token
|
|
@@ -224,7 +230,7 @@ class OAuth2Client {
|
|
|
224
230
|
break;
|
|
225
231
|
}
|
|
226
232
|
catch (responseError) {
|
|
227
|
-
if (options.withCredentials && responseError && responseError.error === ErrorType.UNAUTHENTICATED) {
|
|
233
|
+
if (options.withCredentials && responseError && responseError.error === consts_1.ErrorType.UNAUTHENTICATED) {
|
|
228
234
|
await this.setCredentials(null);
|
|
229
235
|
return Promise.reject(responseError);
|
|
230
236
|
}
|
|
@@ -249,7 +255,7 @@ class OAuth2Client {
|
|
|
249
255
|
retry < OAuth2Client._minRetry ||
|
|
250
256
|
retry > OAuth2Client._maxRetry) {
|
|
251
257
|
responseError = {
|
|
252
|
-
error: ErrorType.UNREACHABLE,
|
|
258
|
+
error: consts_1.ErrorType.UNREACHABLE,
|
|
253
259
|
error_description: 'wrong options param: retry',
|
|
254
260
|
};
|
|
255
261
|
}
|
|
@@ -300,7 +306,7 @@ class OAuth2Client {
|
|
|
300
306
|
return newCredentials;
|
|
301
307
|
}
|
|
302
308
|
catch (error) {
|
|
303
|
-
if (error.error === ErrorType.INVALID_GRANT) {
|
|
309
|
+
if (error.error === consts_1.ErrorType.INVALID_GRANT) {
|
|
304
310
|
await this._localCredentials.setCredentials(null);
|
|
305
311
|
return this._unAuthenticatedError(error.error_description);
|
|
306
312
|
}
|
|
@@ -328,7 +334,7 @@ class OAuth2Client {
|
|
|
328
334
|
return newCredentials;
|
|
329
335
|
}
|
|
330
336
|
catch (error) {
|
|
331
|
-
if (error.error === ErrorType.INVALID_GRANT) {
|
|
337
|
+
if (error.error === consts_1.ErrorType.INVALID_GRANT) {
|
|
332
338
|
await this._localCredentials.setCredentials(null);
|
|
333
339
|
return this._unAuthenticatedError(error.error_description);
|
|
334
340
|
}
|
|
@@ -383,7 +389,7 @@ class OAuth2Client {
|
|
|
383
389
|
if (!(typeof deviceId === 'string' &&
|
|
384
390
|
deviceId.length >= 16 &&
|
|
385
391
|
deviceId.length <= 48)) {
|
|
386
|
-
deviceId = uuidv4();
|
|
392
|
+
deviceId = (0, uuid_1.uuidv4)();
|
|
387
393
|
await this._storage.setItem(DeviceIdSectionName, deviceId);
|
|
388
394
|
}
|
|
389
395
|
this._deviceID = deviceId;
|
|
@@ -396,7 +402,7 @@ class OAuth2Client {
|
|
|
396
402
|
*/
|
|
397
403
|
_unAuthenticatedError(err) {
|
|
398
404
|
return Promise.reject({
|
|
399
|
-
error: ErrorType.UNAUTHENTICATED,
|
|
405
|
+
error: consts_1.ErrorType.UNAUTHENTICATED,
|
|
400
406
|
error_description: err,
|
|
401
407
|
});
|
|
402
408
|
}
|
|
@@ -405,4 +411,4 @@ OAuth2Client._defaultRetry = 2;
|
|
|
405
411
|
OAuth2Client._minRetry = 0;
|
|
406
412
|
OAuth2Client._maxRetry = 5;
|
|
407
413
|
OAuth2Client._retryInterval = 1000;
|
|
408
|
-
|
|
414
|
+
exports.OAuth2Client = OAuth2Client;
|
package/dist/package.json
CHANGED
package/dist/utils/base64.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.weappJwtDecode = exports.base64_url_decode = exports.weAtob = exports.weBtoa = void 0;
|
|
1
4
|
// weapp jwt-decode
|
|
2
5
|
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
3
6
|
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
4
7
|
// btoa
|
|
5
|
-
|
|
8
|
+
function weBtoa(string) {
|
|
6
9
|
string = String(string);
|
|
7
10
|
var bitmap, a, b, c, result = "", i = 0, rest = string.length % 3;
|
|
8
11
|
for (; i < string.length;) {
|
|
@@ -19,8 +22,9 @@ export function weBtoa(string) {
|
|
|
19
22
|
}
|
|
20
23
|
return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
|
|
21
24
|
}
|
|
25
|
+
exports.weBtoa = weBtoa;
|
|
22
26
|
// atob
|
|
23
|
-
|
|
27
|
+
const weAtob = function (string) {
|
|
24
28
|
string = String(string).replace(/[\t\n\f\r ]+/g, "");
|
|
25
29
|
if (!b64re.test(string))
|
|
26
30
|
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
@@ -41,8 +45,9 @@ export const weAtob = function (string) {
|
|
|
41
45
|
}
|
|
42
46
|
return result;
|
|
43
47
|
};
|
|
48
|
+
exports.weAtob = weAtob;
|
|
44
49
|
function b64DecodeUnicode(str) {
|
|
45
|
-
return decodeURIComponent(weAtob(str).replace(/(.)/g, function (p) {
|
|
50
|
+
return decodeURIComponent((0, exports.weAtob)(str).replace(/(.)/g, function (p) {
|
|
46
51
|
var code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
47
52
|
if (code.length < 2) {
|
|
48
53
|
code = "0" + code;
|
|
@@ -50,7 +55,7 @@ function b64DecodeUnicode(str) {
|
|
|
50
55
|
return "%" + code;
|
|
51
56
|
}));
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
function base64_url_decode(str) {
|
|
54
59
|
var output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
55
60
|
switch (output.length % 4) {
|
|
56
61
|
case 0:
|
|
@@ -68,10 +73,11 @@ export function base64_url_decode(str) {
|
|
|
68
73
|
return b64DecodeUnicode(output);
|
|
69
74
|
}
|
|
70
75
|
catch (err) {
|
|
71
|
-
return weAtob(output);
|
|
76
|
+
return (0, exports.weAtob)(output);
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
|
-
|
|
79
|
+
exports.base64_url_decode = base64_url_decode;
|
|
80
|
+
function weappJwtDecode(token, options) {
|
|
75
81
|
if (typeof token !== "string") {
|
|
76
82
|
throw new Error("Invalid token specified");
|
|
77
83
|
}
|
|
@@ -84,3 +90,4 @@ export function weappJwtDecode(token, options) {
|
|
|
84
90
|
throw new Error("Invalid token specified: " + e ? e.message : "");
|
|
85
91
|
}
|
|
86
92
|
}
|
|
93
|
+
exports.weappJwtDecode = weappJwtDecode;
|
package/dist/utils/mp.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInMpWebView = exports.isMp = void 0;
|
|
4
|
+
function isMp() {
|
|
2
5
|
const wx = globalThis.wx;
|
|
3
6
|
if (typeof wx === 'undefined') {
|
|
4
7
|
return false;
|
|
@@ -34,6 +37,7 @@ export function isMp() {
|
|
|
34
37
|
}
|
|
35
38
|
return true;
|
|
36
39
|
}
|
|
40
|
+
exports.isMp = isMp;
|
|
37
41
|
let IS_IN_MP_WEBVIEW = false;
|
|
38
42
|
function ready() {
|
|
39
43
|
IS_IN_MP_WEBVIEW =
|
|
@@ -54,6 +58,7 @@ try {
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
catch (e) { }
|
|
57
|
-
|
|
61
|
+
function isInMpWebView() {
|
|
58
62
|
return IS_IN_MP_WEBVIEW;
|
|
59
63
|
}
|
|
64
|
+
exports.isInMpWebView = isInMpWebView;
|
package/dist/utils/promise.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromiseOnce = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Promise Once
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
class PromiseOnce {
|
|
5
8
|
constructor() {
|
|
6
9
|
this._fnPromiseMap = new Map();
|
|
7
10
|
}
|
|
@@ -41,3 +44,4 @@ export class PromiseOnce {
|
|
|
41
44
|
return Promise.resolve();
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
exports.PromiseOnce = PromiseOnce;
|
package/dist/utils/uuid.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uuidv4 = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Generate uuidv4 string.
|
|
3
6
|
* @return {string}
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function uuidv4() {
|
|
6
9
|
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
7
10
|
const r = (Math.random() * 16) | 0;
|
|
8
11
|
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
9
12
|
return v.toString(16);
|
|
10
13
|
});
|
|
11
14
|
}
|
|
15
|
+
exports.uuidv4 = uuidv4;
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"sourceMap": false,
|
|
4
4
|
"strict": true,
|
|
5
5
|
"noImplicitReturns": true,
|
|
6
|
-
"module": "
|
|
6
|
+
"module": "commonjs",
|
|
7
7
|
"target": "es2020",
|
|
8
8
|
"outDir": "dist",
|
|
9
9
|
"alwaysStrict": true,
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"esModuleInterop": true,
|
|
16
16
|
"lib": ["dom", "es6", "es2020"],
|
|
17
17
|
"baseUrl": "./",
|
|
18
|
-
"moduleResolution": "Node",
|
|
19
18
|
"paths": {}
|
|
20
19
|
},
|
|
21
20
|
"include": ["./src/**/*"],
|