@salesforce/core 3.6.5 → 3.7.2
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/CHANGELOG.md +38 -12
- package/lib/config/config.d.ts +4 -0
- package/lib/config/config.js +4 -0
- package/lib/deviceOauthService.d.ts +3 -3
- package/lib/deviceOauthService.js +17 -18
- package/lib/exported.d.ts +3 -4
- package/lib/exported.js +1 -2
- package/lib/global.js +1 -1
- package/lib/logger.d.ts +1 -1
- package/lib/logger.js +1 -1
- package/lib/org/authInfo.d.ts +15 -40
- package/lib/org/authInfo.js +30 -71
- package/lib/org/connection.d.ts +18 -25
- package/lib/org/connection.js +50 -78
- package/lib/org/org.js +4 -5
- package/lib/org/user.d.ts +1 -0
- package/lib/org/user.js +11 -2
- package/lib/status/pollingClient.d.ts +2 -1
- package/lib/status/streamingClient.d.ts +3 -77
- package/lib/status/streamingClient.js +3 -9
- package/lib/testSetup.d.ts +4 -3
- package/lib/testSetup.js +1 -1
- package/lib/util/getJwtAudienceUrl.d.ts +2 -2
- package/lib/util/sfdcUrl.js +1 -0
- package/lib/webOAuthServer.d.ts +2 -3
- package/lib/webOAuthServer.js +2 -1
- package/messages/config.md +6 -2
- package/package.json +5 -2
- package/lib/status/client.d.ts +0 -15
- package/lib/status/client.js +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,47 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [3.
|
|
5
|
+
### [3.7.2](https://github.com/forcedotcom/sfdx-core/compare/v3.7.1...v3.7.2) (2021-10-28)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
### Bug Fixes
|
|
9
9
|
|
|
10
|
-
*
|
|
10
|
+
* make @types/sfdx-faye a dependendcy ([683680b](https://github.com/forcedotcom/sfdx-core/commit/683680b8133048f71d25ef4df7aa24d9700dc5e8))
|
|
11
11
|
|
|
12
|
-
### [3.
|
|
12
|
+
### [3.7.1](https://github.com/forcedotcom/sfdx-core/compare/v3.7.0...v3.7.1) (2021-10-28)
|
|
13
|
+
|
|
14
|
+
## [3.7.0](https://github.com/forcedotcom/sfdx-core/compare/v3.6.6...v3.7.0) (2021-10-12)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* use jsforce v2 ([#457](https://github.com/forcedotcom/sfdx-core/issues/457)) ([4a9094e](https://github.com/forcedotcom/sfdx-core/commit/4a9094e958288cdcc6c69f5d87b10a70a437d8e9))
|
|
13
20
|
|
|
21
|
+
### [3.6.6](https://github.com/forcedotcom/sfdx-core/compare/v3.6.5...v3.6.6) (2021-10-08)
|
|
22
|
+
|
|
23
|
+
### [3.6.5](https://github.com/forcedotcom/sfdx-core/compare/v3.6.4...v3.6.5) (2021-09-29)
|
|
14
24
|
|
|
15
25
|
### Bug Fixes
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
- add getValue to AliasAccessor ([c4b69f5](https://github.com/forcedotcom/sfdx-core/commit/c4b69f5ff38547fad640c64833291fe0c6e06a79))
|
|
18
28
|
|
|
19
|
-
### [3.6.
|
|
29
|
+
### [3.6.4](https://github.com/forcedotcom/sfdx-core/compare/v3.6.3...v3.6.4) (2021-09-23)
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
20
32
|
|
|
33
|
+
- edit the env var blurbs ([#482](https://github.com/forcedotcom/sfdx-core/issues/482)) ([bbbdb6d](https://github.com/forcedotcom/sfdx-core/commit/bbbdb6d0800015e94ce0f0c551eec8ed73dd87c6))
|
|
34
|
+
|
|
35
|
+
### [3.6.3](https://github.com/forcedotcom/sfdx-core/compare/v3.6.2...v3.6.3) (2021-09-23)
|
|
21
36
|
|
|
22
37
|
### Bug Fixes
|
|
23
38
|
|
|
24
|
-
|
|
39
|
+
- edit the config var blurbs ([#480](https://github.com/forcedotcom/sfdx-core/issues/480)) ([f845512](https://github.com/forcedotcom/sfdx-core/commit/f8455121bfd96f27495bc124dc06570632dfce70))
|
|
25
40
|
|
|
26
41
|
### [3.6.2](https://github.com/forcedotcom/sfdx-core/compare/v3.6.1...v3.6.2) (2021-09-17)
|
|
27
42
|
|
|
28
|
-
|
|
29
43
|
### Bug Fixes
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
- improve time to build auths for many orgs @W-9914839@ ([#478](https://github.com/forcedotcom/sfdx-core/issues/478)) ([c788541](https://github.com/forcedotcom/sfdx-core/commit/c7885415d59994b28552227f0b84dcee5d3ec7cf))
|
|
32
46
|
|
|
33
47
|
### [3.6.1](https://github.com/forcedotcom/sfdx-core/compare/v3.6.0...v3.6.1) (2021-09-13)
|
|
34
48
|
|
|
35
|
-
|
|
36
49
|
### Bug Fixes
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
- remove tokens associated with org ([#477](https://github.com/forcedotcom/sfdx-core/issues/477)) ([5034fa2](https://github.com/forcedotcom/sfdx-core/commit/5034fa2d4c52d347c00499e137a71366e4feba7f))
|
|
39
52
|
|
|
40
53
|
## [3.6.0](https://github.com/forcedotcom/sfdx-core/compare/v3.5.0...v3.6.0) (2021-09-10)
|
|
41
54
|
|
|
42
|
-
|
|
43
55
|
### Features
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
- add help section helper ([#474](https://github.com/forcedotcom/sfdx-core/issues/474)) ([b34c2d7](https://github.com/forcedotcom/sfdx-core/commit/b34c2d7a442aed2cf091fd394a7c3656287d1dbf))
|
|
46
58
|
|
|
47
59
|
## [3.5.0](https://github.com/forcedotcom/sfdx-core/compare/v3.4.5...v3.5.0) (2021-09-09)
|
|
48
60
|
|
|
@@ -210,6 +222,20 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
210
222
|
- add GlobalInfo config file ([#397](https://github.com/forcedotcom/sfdx-core/issues/397)) ([579998b](https://github.com/forcedotcom/sfdx-core/commit/579998b6ee70dbb9772e65896bbabf6d812aae23))
|
|
211
223
|
- default to reading files from cache ([12b5930](https://github.com/forcedotcom/sfdx-core/commit/12b59301df96395c4edcbfb0816dbddd45af95db))
|
|
212
224
|
|
|
225
|
+
### [2.28.1](https://github.com/forcedotcom/sfdx-core/compare/v2.28.0...v2.28.1) (2021-10-06)
|
|
226
|
+
|
|
227
|
+
### Bug Fixes
|
|
228
|
+
|
|
229
|
+
- crmforce.mil ([e263d5d](https://github.com/forcedotcom/sfdx-core/commit/e263d5d74be9c0651e5c2676d6eec1c31fca05e4))
|
|
230
|
+
|
|
231
|
+
## [2.28.0](https://github.com/forcedotcom/sfdx-core/compare/v2.27.2...v2.28.0) (2021-09-16)
|
|
232
|
+
|
|
233
|
+
### Features
|
|
234
|
+
|
|
235
|
+
- add custom templates config ([3cf8a8c](https://github.com/forcedotcom/sfdx-core/commit/3cf8a8cee1e7196efced989dcca9b545e1283386))
|
|
236
|
+
- add validator for custom templates config ([dd2bcfe](https://github.com/forcedotcom/sfdx-core/commit/dd2bcfe8e7fee5c5c1c6321189ec04288103d5b6))
|
|
237
|
+
- update config name ([72e84bf](https://github.com/forcedotcom/sfdx-core/commit/72e84bfacef48a1c2d00a61ebbae3f632601abbd))
|
|
238
|
+
|
|
213
239
|
### [2.27.2](https://github.com/forcedotcom/sfdx-core/compare/v2.27.1...v2.27.2) (2021-08-05)
|
|
214
240
|
|
|
215
241
|
### Bug Fixes
|
package/lib/config/config.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export declare enum SfdxPropertyKeys {
|
|
|
80
80
|
* Disables telemetry reporting
|
|
81
81
|
*/
|
|
82
82
|
DISABLE_TELEMETRY = "disableTelemetry",
|
|
83
|
+
/**
|
|
84
|
+
* Custom templates repo or local location.
|
|
85
|
+
*/
|
|
86
|
+
CUSTOM_ORG_METADATA_TEMPLATES = "customOrgMetadataTemplates",
|
|
83
87
|
/**
|
|
84
88
|
* allows users to override the 10,000 result query limit
|
|
85
89
|
*/
|
package/lib/config/config.js
CHANGED
|
@@ -73,6 +73,10 @@ var SfdxPropertyKeys;
|
|
|
73
73
|
* Disables telemetry reporting
|
|
74
74
|
*/
|
|
75
75
|
SfdxPropertyKeys["DISABLE_TELEMETRY"] = "disableTelemetry";
|
|
76
|
+
/**
|
|
77
|
+
* Custom templates repo or local location.
|
|
78
|
+
*/
|
|
79
|
+
SfdxPropertyKeys["CUSTOM_ORG_METADATA_TEMPLATES"] = "customOrgMetadataTemplates";
|
|
76
80
|
/**
|
|
77
81
|
* allows users to override the 10,000 result query limit
|
|
78
82
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncCreatable } from '@salesforce/kit';
|
|
2
|
-
import {
|
|
2
|
+
import { OAuth2Config } from 'jsforce/lib/oauth2';
|
|
3
3
|
import { Nullable, JsonMap } from '@salesforce/ts-types';
|
|
4
4
|
import { AuthInfo } from './org/authInfo';
|
|
5
5
|
export interface DeviceCodeResponse extends JsonMap {
|
|
@@ -34,7 +34,7 @@ export interface DeviceCodePollingResponse extends JsonMap {
|
|
|
34
34
|
* const authInfo = await deviceOauthService.authorizeAndSave(approval);
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export declare class DeviceOauthService extends AsyncCreatable<
|
|
37
|
+
export declare class DeviceOauthService extends AsyncCreatable<OAuth2Config> {
|
|
38
38
|
static RESPONSE_TYPE: string;
|
|
39
39
|
static GRANT_TYPE: string;
|
|
40
40
|
static SCOPE: string;
|
|
@@ -42,7 +42,7 @@ export declare class DeviceOauthService extends AsyncCreatable<OAuth2Options> {
|
|
|
42
42
|
private logger;
|
|
43
43
|
private options;
|
|
44
44
|
private pollingCount;
|
|
45
|
-
constructor(options:
|
|
45
|
+
constructor(options: OAuth2Config);
|
|
46
46
|
/**
|
|
47
47
|
* Begin the authorization flow by requesting the login
|
|
48
48
|
*
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.DeviceOauthService = void 0;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const Transport = require("jsforce/lib/transport");
|
|
12
|
+
const url_1 = require("url");
|
|
13
|
+
const transport_1 = require("jsforce/lib/transport");
|
|
15
14
|
const kit_1 = require("@salesforce/kit");
|
|
16
15
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
17
16
|
const logger_1 = require("./logger");
|
|
@@ -27,7 +26,7 @@ async function wait(ms = 1000) {
|
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
28
|
async function makeRequest(options) {
|
|
30
|
-
const rawResponse = await new
|
|
29
|
+
const rawResponse = await new transport_1.default().httpRequest(options);
|
|
31
30
|
const response = kit_1.parseJsonMap(rawResponse.body);
|
|
32
31
|
if (response.error) {
|
|
33
32
|
const err = new sfdxError_1.SfdxError('Request Failed.');
|
|
@@ -109,36 +108,36 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
|
109
108
|
this.logger.debug(`this.options.loginUrl: ${this.options.loginUrl}`);
|
|
110
109
|
}
|
|
111
110
|
getLoginOptions(url) {
|
|
111
|
+
const body = new url_1.URLSearchParams();
|
|
112
|
+
body.append('client_id', ts_types_1.ensureString(this.options.clientId));
|
|
113
|
+
body.append('response_type', DeviceOauthService.RESPONSE_TYPE);
|
|
114
|
+
body.append('scope', DeviceOauthService.SCOPE);
|
|
112
115
|
return {
|
|
113
116
|
url,
|
|
114
117
|
headers: connection_1.SFDX_HTTP_HEADERS,
|
|
115
118
|
method: 'POST',
|
|
116
|
-
|
|
117
|
-
client_id: ts_types_1.ensureString(this.options.clientId),
|
|
118
|
-
response_type: DeviceOauthService.RESPONSE_TYPE,
|
|
119
|
-
scope: DeviceOauthService.SCOPE,
|
|
120
|
-
},
|
|
119
|
+
body,
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
getPollingOptions(url, code) {
|
|
123
|
+
const body = new url_1.URLSearchParams();
|
|
124
|
+
body.append('client_id', ts_types_1.ensureString(this.options.clientId));
|
|
125
|
+
body.append('grant_type', DeviceOauthService.GRANT_TYPE);
|
|
126
|
+
body.append('code', code);
|
|
124
127
|
return {
|
|
125
128
|
url,
|
|
126
129
|
headers: connection_1.SFDX_HTTP_HEADERS,
|
|
127
130
|
method: 'POST',
|
|
128
|
-
|
|
129
|
-
code,
|
|
130
|
-
grant_type: DeviceOauthService.GRANT_TYPE,
|
|
131
|
-
client_id: ts_types_1.ensureString(this.options.clientId),
|
|
132
|
-
},
|
|
131
|
+
body,
|
|
133
132
|
};
|
|
134
133
|
}
|
|
135
134
|
getDeviceFlowRequestUrl() {
|
|
136
135
|
return `${ts_types_1.ensureString(this.options.loginUrl)}/services/oauth2/token`;
|
|
137
136
|
}
|
|
138
|
-
async poll(
|
|
137
|
+
async poll(httpRequest) {
|
|
139
138
|
this.logger.debug(`polling for device approval (attempt ${this.pollingCount} of ${DeviceOauthService.POLLING_COUNT_MAX})`);
|
|
140
139
|
try {
|
|
141
|
-
return await makeRequest(
|
|
140
|
+
return await makeRequest(httpRequest);
|
|
142
141
|
}
|
|
143
142
|
catch (e) {
|
|
144
143
|
const err = e.data;
|
|
@@ -160,11 +159,11 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
|
160
159
|
shouldContinuePolling() {
|
|
161
160
|
return this.pollingCount < DeviceOauthService.POLLING_COUNT_MAX;
|
|
162
161
|
}
|
|
163
|
-
async pollForDeviceApproval(
|
|
162
|
+
async pollForDeviceApproval(httpRequest, interval) {
|
|
164
163
|
this.logger.debug('BEGIN POLLING FOR DEVICE APPROVAL');
|
|
165
164
|
let result;
|
|
166
165
|
while (this.shouldContinuePolling()) {
|
|
167
|
-
result = await this.poll(
|
|
166
|
+
result = await this.poll(httpRequest);
|
|
168
167
|
if (result) {
|
|
169
168
|
this.logger.debug('POLLING FOR DEVICE APPROVAL SUCCESS');
|
|
170
169
|
break;
|
package/lib/exported.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { OAuth2Config } from 'jsforce';
|
|
2
2
|
export { ConfigFile } from './config/configFile';
|
|
3
3
|
export { EnvironmentVariable, SUPPORTED_ENV_VARS } from './config/envVars';
|
|
4
4
|
export { BaseConfigStore, ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
@@ -7,7 +7,7 @@ export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } fro
|
|
|
7
7
|
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
8
8
|
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SFDX_ALLOWED_PROPERTIES, } from './config/config';
|
|
9
9
|
export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
|
|
10
|
-
export { AuthFields, AuthInfo,
|
|
10
|
+
export { AuthFields, AuthInfo, OrgAuthorization } from './org/authInfo';
|
|
11
11
|
export { AuthRemover } from './org/authRemover';
|
|
12
12
|
export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
|
|
13
13
|
export { Mode, Global } from './global';
|
|
@@ -23,9 +23,8 @@ export { PackageDir, NamedPackageDir, PackageDirDependency, SfdxProject, SfdxPro
|
|
|
23
23
|
export { SchemaPrinter } from './schema/printer';
|
|
24
24
|
export { SchemaValidator } from './schema/validator';
|
|
25
25
|
export { SfdxError } from './sfdxError';
|
|
26
|
-
export { StatusResult } from './status/client';
|
|
27
26
|
export { PollingClient } from './status/pollingClient';
|
|
28
|
-
export { CometClient, CometSubscription, StreamingClient } from './status/streamingClient';
|
|
27
|
+
export { CometClient, CometSubscription, StreamingClient, StatusResult } from './status/streamingClient';
|
|
29
28
|
export { MyDomainResolver } from './status/myDomainResolver';
|
|
30
29
|
export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
|
|
31
30
|
export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
|
package/lib/exported.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.
|
|
19
|
+
exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.ConfigAggregator = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.ConfigFile = void 0;
|
|
20
20
|
const messages_1 = require("./messages");
|
|
21
21
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
22
22
|
var configFile_1 = require("./config/configFile");
|
|
@@ -41,7 +41,6 @@ var configAggregator_1 = require("./config/configAggregator");
|
|
|
41
41
|
Object.defineProperty(exports, "ConfigAggregator", { enumerable: true, get: function () { return configAggregator_1.ConfigAggregator; } });
|
|
42
42
|
var authInfo_1 = require("./org/authInfo");
|
|
43
43
|
Object.defineProperty(exports, "AuthInfo", { enumerable: true, get: function () { return authInfo_1.AuthInfo; } });
|
|
44
|
-
Object.defineProperty(exports, "OAuth2WithVerifier", { enumerable: true, get: function () { return authInfo_1.OAuth2WithVerifier; } });
|
|
45
44
|
var authRemover_1 = require("./org/authRemover");
|
|
46
45
|
Object.defineProperty(exports, "AuthRemover", { enumerable: true, get: function () { return authRemover_1.AuthRemover; } });
|
|
47
46
|
var connection_1 = require("./org/connection");
|
package/lib/global.js
CHANGED
|
@@ -79,5 +79,5 @@ Global.SF_DIR = path.join(os.homedir(), Global.SF_STATE_FOLDER);
|
|
|
79
79
|
/**
|
|
80
80
|
* The full system path to the global log file.
|
|
81
81
|
*/
|
|
82
|
-
Global.LOG_FILE_PATH = path.join(Global.
|
|
82
|
+
Global.LOG_FILE_PATH = path.join(Global.SF_DIR, 'sf.log');
|
|
83
83
|
//# sourceMappingURL=global.js.map
|
package/lib/logger.d.ts
CHANGED
|
@@ -150,7 +150,7 @@ export declare class Logger {
|
|
|
150
150
|
/**
|
|
151
151
|
* The name of the root sfdx `Logger`.
|
|
152
152
|
*/
|
|
153
|
-
static readonly ROOT_NAME = "
|
|
153
|
+
static readonly ROOT_NAME = "sf";
|
|
154
154
|
/**
|
|
155
155
|
* The default `LoggerLevel` when constructing new `Logger` instances.
|
|
156
156
|
*/
|
package/lib/logger.js
CHANGED
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
-
import {
|
|
3
|
-
import { OAuth2,
|
|
2
|
+
import { Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { OAuth2, OAuth2Config as JsforceOAuth2Config } from 'jsforce';
|
|
4
4
|
import { Connection } from './connection';
|
|
5
|
+
export declare type OAuth2Config = JsforceOAuth2Config & {
|
|
6
|
+
privateKey?: string;
|
|
7
|
+
privateKeyFile?: string;
|
|
8
|
+
authCode?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
loginUrl?: string;
|
|
11
|
+
};
|
|
5
12
|
/**
|
|
6
13
|
* Fields for authorization, org, and local information.
|
|
7
14
|
*/
|
|
@@ -63,46 +70,12 @@ export declare type ConnectionOptions = AuthFields & {
|
|
|
63
70
|
/**
|
|
64
71
|
* OAuth options.
|
|
65
72
|
*/
|
|
66
|
-
oauth2?: Partial<
|
|
73
|
+
oauth2?: Partial<OAuth2Config>;
|
|
67
74
|
/**
|
|
68
75
|
* Refresh token callback.
|
|
69
76
|
*/
|
|
70
77
|
refreshFn?: RefreshFn;
|
|
71
78
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Extend OAuth2 to add code verifier support for the auth code (web auth) flow
|
|
74
|
-
* const oauth2 = new OAuth2WithVerifier({ loginUrl, clientSecret, clientId, redirectUri });
|
|
75
|
-
*
|
|
76
|
-
* const authUrl = oauth2.getAuthorizationUrl({
|
|
77
|
-
* state: 'foo',
|
|
78
|
-
* prompt: 'login',
|
|
79
|
-
* scope: 'api web'
|
|
80
|
-
* });
|
|
81
|
-
* console.log(authUrl);
|
|
82
|
-
* const authCode = await retrieveCode();
|
|
83
|
-
* const authInfo = await AuthInfo.create({ oauth2Options: { clientId, clientSecret, loginUrl, authCode }, oauth2});
|
|
84
|
-
* console.log(`access token: ${authInfo.getFields(true).accessToken}`);
|
|
85
|
-
*/
|
|
86
|
-
export declare class OAuth2WithVerifier extends OAuth2 {
|
|
87
|
-
readonly codeVerifier: string;
|
|
88
|
-
constructor(options: OAuth2Options);
|
|
89
|
-
/**
|
|
90
|
-
* Overrides jsforce.OAuth2.getAuthorizationUrl. Get Salesforce OAuth2 authorization page
|
|
91
|
-
* URL to redirect user agent, adding a verification code for added security.
|
|
92
|
-
*
|
|
93
|
-
* @param params
|
|
94
|
-
*/
|
|
95
|
-
getAuthorizationUrl(params: Record<string, unknown>): string;
|
|
96
|
-
requestToken(code: string, callback?: (err: Error, tokenResponse: TokenResponse) => void): Promise<TokenResponse>;
|
|
97
|
-
/**
|
|
98
|
-
* Overrides jsforce.OAuth2._postParams because jsforce's oauth impl doesn't support
|
|
99
|
-
* coder_verifier and code_challenge. This enables the server to disallow trading a one-time auth code
|
|
100
|
-
* for an access/refresh token when the verifier and challenge are out of alignment.
|
|
101
|
-
*
|
|
102
|
-
* See https://github.com/jsforce/jsforce/issues/665
|
|
103
|
-
*/
|
|
104
|
-
protected _postParams(params: Record<string, unknown>, callback: AnyFunction): Promise<any>;
|
|
105
|
-
}
|
|
106
79
|
export declare const DEFAULT_CONNECTED_APP_INFO: {
|
|
107
80
|
clientId: string;
|
|
108
81
|
legacyClientId: string;
|
|
@@ -180,9 +153,9 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
180
153
|
*
|
|
181
154
|
* @param options The options to generate the URL.
|
|
182
155
|
*/
|
|
183
|
-
static getAuthorizationUrl(options:
|
|
156
|
+
static getAuthorizationUrl(options: OAuth2Config & {
|
|
184
157
|
scope?: string;
|
|
185
|
-
}, oauth2?:
|
|
158
|
+
}, oauth2?: OAuth2): string;
|
|
186
159
|
/**
|
|
187
160
|
* Parse a sfdx auth url, usually obtained by `authInfo.getSfdxAuthUrl`.
|
|
188
161
|
*
|
|
@@ -235,6 +208,8 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
235
208
|
* Get the auth fields (decrypted) needed to make a connection.
|
|
236
209
|
*/
|
|
237
210
|
getConnectionOptions(): ConnectionOptions;
|
|
211
|
+
getClientId(): string;
|
|
212
|
+
getRedirectUri(): string;
|
|
238
213
|
/**
|
|
239
214
|
* Get the authorization fields.
|
|
240
215
|
*
|
|
@@ -320,7 +295,7 @@ export declare namespace AuthInfo {
|
|
|
320
295
|
/**
|
|
321
296
|
* OAuth options.
|
|
322
297
|
*/
|
|
323
|
-
oauth2Options?:
|
|
298
|
+
oauth2Options?: OAuth2Config;
|
|
324
299
|
/**
|
|
325
300
|
* Options for the access token auth.
|
|
326
301
|
*/
|
package/lib/org/authInfo.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO =
|
|
9
|
+
exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = void 0;
|
|
10
10
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
11
11
|
const crypto_1 = require("crypto");
|
|
12
12
|
const path_1 = require("path");
|
|
@@ -14,9 +14,7 @@ const os = require("os");
|
|
|
14
14
|
const kit_1 = require("@salesforce/kit");
|
|
15
15
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
16
16
|
const jsforce_1 = require("jsforce");
|
|
17
|
-
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const Transport = require("jsforce/lib/transport");
|
|
17
|
+
const transport_1 = require("jsforce/lib/transport");
|
|
20
18
|
const jwt = require("jsonwebtoken");
|
|
21
19
|
const config_1 = require("../config/config");
|
|
22
20
|
const configAggregator_1 = require("../config/configAggregator");
|
|
@@ -46,65 +44,15 @@ class JwtOAuth2 extends jsforce_1.OAuth2 {
|
|
|
46
44
|
constructor(options) {
|
|
47
45
|
super(options);
|
|
48
46
|
}
|
|
49
|
-
jwtAuthorize(innerToken
|
|
47
|
+
jwtAuthorize(innerToken) {
|
|
50
48
|
// @ts-ignore
|
|
51
49
|
return super._postParams({
|
|
52
50
|
// eslint-disable-next-line camelcase
|
|
53
51
|
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
54
52
|
assertion: innerToken,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Extend OAuth2 to add code verifier support for the auth code (web auth) flow
|
|
60
|
-
* const oauth2 = new OAuth2WithVerifier({ loginUrl, clientSecret, clientId, redirectUri });
|
|
61
|
-
*
|
|
62
|
-
* const authUrl = oauth2.getAuthorizationUrl({
|
|
63
|
-
* state: 'foo',
|
|
64
|
-
* prompt: 'login',
|
|
65
|
-
* scope: 'api web'
|
|
66
|
-
* });
|
|
67
|
-
* console.log(authUrl);
|
|
68
|
-
* const authCode = await retrieveCode();
|
|
69
|
-
* const authInfo = await AuthInfo.create({ oauth2Options: { clientId, clientSecret, loginUrl, authCode }, oauth2});
|
|
70
|
-
* console.log(`access token: ${authInfo.getFields(true).accessToken}`);
|
|
71
|
-
*/
|
|
72
|
-
class OAuth2WithVerifier extends jsforce_1.OAuth2 {
|
|
73
|
-
constructor(options) {
|
|
74
|
-
super(options);
|
|
75
|
-
// Set a code verifier string for OAuth authorization
|
|
76
|
-
this.codeVerifier = base64UrlEscape(crypto_1.randomBytes(Math.ceil(128)).toString('base64'));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Overrides jsforce.OAuth2.getAuthorizationUrl. Get Salesforce OAuth2 authorization page
|
|
80
|
-
* URL to redirect user agent, adding a verification code for added security.
|
|
81
|
-
*
|
|
82
|
-
* @param params
|
|
83
|
-
*/
|
|
84
|
-
getAuthorizationUrl(params) {
|
|
85
|
-
// code verifier must be a base 64 url encoded hash of 128 bytes of random data. Our random data is also
|
|
86
|
-
// base 64 url encoded. See Connection.create();
|
|
87
|
-
const codeChallenge = base64UrlEscape(crypto_1.createHash('sha256').update(this.codeVerifier).digest('base64'));
|
|
88
|
-
kit_1.set(params, 'code_challenge', codeChallenge);
|
|
89
|
-
return super.getAuthorizationUrl(params);
|
|
90
|
-
}
|
|
91
|
-
async requestToken(code, callback) {
|
|
92
|
-
return super.requestToken(code, callback);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Overrides jsforce.OAuth2._postParams because jsforce's oauth impl doesn't support
|
|
96
|
-
* coder_verifier and code_challenge. This enables the server to disallow trading a one-time auth code
|
|
97
|
-
* for an access/refresh token when the verifier and challenge are out of alignment.
|
|
98
|
-
*
|
|
99
|
-
* See https://github.com/jsforce/jsforce/issues/665
|
|
100
|
-
*/
|
|
101
|
-
async _postParams(params, callback) {
|
|
102
|
-
kit_1.set(params, 'code_verifier', this.codeVerifier);
|
|
103
|
-
// @ts-ignore TODO: need better typings for jsforce
|
|
104
|
-
return super._postParams(params, callback);
|
|
53
|
+
});
|
|
105
54
|
}
|
|
106
55
|
}
|
|
107
|
-
exports.OAuth2WithVerifier = OAuth2WithVerifier;
|
|
108
56
|
// parses the id field returned from jsForce oauth2 methods to get
|
|
109
57
|
// user ID and org ID.
|
|
110
58
|
function parseIdUrl(idUrl) {
|
|
@@ -129,13 +77,6 @@ exports.DEFAULT_CONNECTED_APP_INFO = {
|
|
|
129
77
|
legacyClientId: 'SalesforceDevelopmentExperience',
|
|
130
78
|
legacyClientSecret: '1384510088588713504',
|
|
131
79
|
};
|
|
132
|
-
// Makes a nodejs base64 encoded string compatible with rfc4648 alternative encoding for urls.
|
|
133
|
-
// @param base64Encoded a nodejs base64 encoded string
|
|
134
|
-
function base64UrlEscape(base64Encoded) {
|
|
135
|
-
// builtin node js base 64 encoding is not 64 url compatible.
|
|
136
|
-
// See https://toolsn.ietf.org/html/rfc4648#section-5
|
|
137
|
-
return base64Encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
138
|
-
}
|
|
139
80
|
/**
|
|
140
81
|
* Handles persistence and fetching of user authentication information using
|
|
141
82
|
* JWT, OAuth, or refresh tokens. Sets up the refresh flows that jsForce will
|
|
@@ -270,7 +211,9 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
270
211
|
* @param options The options to generate the URL.
|
|
271
212
|
*/
|
|
272
213
|
static getAuthorizationUrl(options, oauth2) {
|
|
273
|
-
|
|
214
|
+
// Always use a verifier for enhanced security
|
|
215
|
+
options.useVerifier = true;
|
|
216
|
+
const oauth2Verifier = oauth2 || new jsforce_1.OAuth2(options);
|
|
274
217
|
// The state parameter allows the redirectUri callback listener to ignore request
|
|
275
218
|
// that don't contain the state value.
|
|
276
219
|
const params = {
|
|
@@ -399,8 +342,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
399
342
|
opts = {
|
|
400
343
|
oauth2: {
|
|
401
344
|
loginUrl: instanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION,
|
|
402
|
-
clientId:
|
|
403
|
-
redirectUri:
|
|
345
|
+
clientId: this.getClientId(),
|
|
346
|
+
redirectUri: this.getRedirectUri(),
|
|
404
347
|
},
|
|
405
348
|
accessToken,
|
|
406
349
|
instanceUrl,
|
|
@@ -410,6 +353,13 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
410
353
|
// decrypt the fields
|
|
411
354
|
return opts;
|
|
412
355
|
}
|
|
356
|
+
getClientId() {
|
|
357
|
+
var _a;
|
|
358
|
+
return ((_a = this.getFields()) === null || _a === void 0 ? void 0 : _a.clientId) || exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId;
|
|
359
|
+
}
|
|
360
|
+
getRedirectUri() {
|
|
361
|
+
return 'http://localhost:1717/OauthRedirect';
|
|
362
|
+
}
|
|
413
363
|
/**
|
|
414
364
|
* Get the authorization fields.
|
|
415
365
|
*
|
|
@@ -581,7 +531,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
581
531
|
authConfig = await this.buildRefreshTokenConfig(options);
|
|
582
532
|
}
|
|
583
533
|
else {
|
|
584
|
-
if (this.options.oauth2 instanceof
|
|
534
|
+
if (this.options.oauth2 instanceof jsforce_1.OAuth2) {
|
|
585
535
|
// authcode exchange / web auth flow
|
|
586
536
|
authConfig = await this.exchangeToken(options, this.options.oauth2);
|
|
587
537
|
}
|
|
@@ -604,8 +554,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
604
554
|
return authInfo;
|
|
605
555
|
}
|
|
606
556
|
isTokenOptions(options) {
|
|
607
|
-
// Although
|
|
608
|
-
// which WILL have an access token as well, but it should be considered an
|
|
557
|
+
// Although OAuth2Config does not contain refreshToken, privateKey, or privateKeyFile, a JS consumer could still pass those in
|
|
558
|
+
// which WILL have an access token as well, but it should be considered an OAuth2Config at that point.
|
|
609
559
|
return ('accessToken' in options &&
|
|
610
560
|
!('refreshToken' in options) &&
|
|
611
561
|
!('privateKey' in options) &&
|
|
@@ -681,6 +631,9 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
681
631
|
options.clientId = exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId;
|
|
682
632
|
options.clientSecret = exports.DEFAULT_CONNECTED_APP_INFO.legacyClientSecret;
|
|
683
633
|
}
|
|
634
|
+
if (!options.redirectUri) {
|
|
635
|
+
options.redirectUri = this.getRedirectUri();
|
|
636
|
+
}
|
|
684
637
|
const oauth2 = new jsforce_1.OAuth2(options);
|
|
685
638
|
let authFieldsBuilder;
|
|
686
639
|
try {
|
|
@@ -717,6 +670,12 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
717
670
|
* @param oauth2 The oauth2 extension that includes a code_challenge
|
|
718
671
|
*/
|
|
719
672
|
async exchangeToken(options, oauth2 = new jsforce_1.OAuth2(options)) {
|
|
673
|
+
if (!oauth2.redirectUri) {
|
|
674
|
+
oauth2.redirectUri = this.getRedirectUri();
|
|
675
|
+
}
|
|
676
|
+
if (!oauth2.clientId) {
|
|
677
|
+
oauth2.clientId = this.getClientId();
|
|
678
|
+
}
|
|
720
679
|
// Exchange the auth code for an access token and refresh token.
|
|
721
680
|
let authFields;
|
|
722
681
|
try {
|
|
@@ -760,7 +719,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
760
719
|
const headers = Object.assign({ Authorization: `Bearer ${accessToken}` }, connection_1.SFDX_HTTP_HEADERS);
|
|
761
720
|
try {
|
|
762
721
|
this.logger.info(`Sending request for Username after successful auth code exchange to URL: ${userInfoUrl}`);
|
|
763
|
-
let response = await new
|
|
722
|
+
let response = await new transport_1.default().httpRequest({ url: userInfoUrl, method: 'GET', headers });
|
|
764
723
|
if (response.statusCode >= 400) {
|
|
765
724
|
this.throwUserGetException(response);
|
|
766
725
|
}
|
|
@@ -768,7 +727,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
768
727
|
const userInfoJson = kit_1.parseJsonMap(response.body);
|
|
769
728
|
const url = `${baseUrl}/services/data/${apiVersion}/sobjects/User/${userInfoJson.user_id}`;
|
|
770
729
|
this.logger.info(`Sending request for User SObject after successful auth code exchange to URL: ${url}`);
|
|
771
|
-
response = await new
|
|
730
|
+
response = await new transport_1.default().httpRequest({ url, method: 'GET', headers });
|
|
772
731
|
if (response.statusCode >= 400) {
|
|
773
732
|
this.throwUserGetException(response);
|
|
774
733
|
}
|