Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"command": "api:request:rest",
"flagAliases": [],
"flagChars": ["H", "S", "X", "b", "f", "i", "o"],
"flags": ["body", "file", "flags-dir", "header", "include", "method", "stream-to-file", "target-org"],
"flags": ["body", "file", "flags-dir", "header", "include", "method", "no-auth", "stream-to-file", "target-org"],
"plugin": "@salesforce/plugin-api"
}
]
6 changes: 5 additions & 1 deletion messages/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ HTTP header in "key:value" format.

# flags.body.summary

File or content for the body of the HTTP request. Specify "-" to read from standard input or "" for an empty body. If passing a file, prefix the filename with '@'.
File or content for the body of the HTTP request. Specify "-" to read from standard input or "" for an empty body. If passing a file, prefix the filename with '@'.

# flags.no-auth.summary

Don't add the "Authorization: Bearer <token>" header to the request.
26 changes: 18 additions & 8 deletions src/commands/api/request/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class Rest extends SfCommand<void> {
helpValue: 'file',
char: 'b',
}),
'no-auth': Flags.boolean({
summary: messages.getMessage('flags.no-auth.summary'),
}),
};

public static args = {
Expand Down Expand Up @@ -138,20 +141,27 @@ export class Rest extends SfCommand<void> {
headers = { ...headers, ...body.getHeaders() };
}

// refresh access token to ensure `got` gets a valid access token.
// TODO: we could skip this step if we used jsforce's HTTP module instead (handles expired tokens).
await org.refreshAuth();
const skipAuth = flags['no-auth'];
if (!skipAuth) {
// refresh access token to ensure `got` gets a valid access token.
// TODO: we could skip this step if we used jsforce's HTTP module instead (handles expired tokens).
await org.refreshAuth();
}

const options = {
agent: { https: new ProxyAgent() },
method,
headers: {
...SFDX_HTTP_HEADERS,
Authorization: `Bearer ${
// we don't care about apiVersion here, just need to get the access token.
// eslint-disable-next-line sf-plugin/get-connection-with-version
org.getConnection().getConnectionOptions().accessToken!
}`,
...(skipAuth
? {}
: {
Authorization: `Bearer ${
// we don't care about apiVersion here, just need to get the access token.
// eslint-disable-next-line sf-plugin/get-connection-with-version
org.getConnection().getConnectionOptions().accessToken!
}`,
}),
...headers,
},
body,
Expand Down
Loading