Skip to content

Commit 83b0661

Browse files
committed
feat: add no-auth flag
1 parent 4d6f9f5 commit 83b0661

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

command-snapshot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"command": "api:request:rest",
1313
"flagAliases": [],
1414
"flagChars": ["H", "S", "X", "b", "f", "i", "o"],
15-
"flags": ["body", "file", "flags-dir", "header", "include", "method", "stream-to-file", "target-org"],
15+
"flags": ["body", "file", "flags-dir", "header", "include", "method", "no-auth", "stream-to-file", "target-org"],
1616
"plugin": "@salesforce/plugin-api"
1717
}
1818
]

messages/rest.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ HTTP header in "key:value" format.
8181

8282
# flags.body.summary
8383

84-
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 '@'.
84+
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 '@'.
85+
86+
# flags.no-auth.summary
87+
88+
Skip the "Authentication" header.

src/commands/api/request/rest.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class Rest extends SfCommand<void> {
8181
helpValue: 'file',
8282
char: 'b',
8383
}),
84+
'no-auth': Flags.boolean({
85+
summary: messages.getMessage('flags.no-auth.summary'),
86+
}),
8487
};
8588

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

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

145151
const options = {
146152
agent: { https: new ProxyAgent() },
147153
method,
148154
headers: {
149155
...SFDX_HTTP_HEADERS,
150-
Authorization: `Bearer ${
151-
// we don't care about apiVersion here, just need to get the access token.
152-
// eslint-disable-next-line sf-plugin/get-connection-with-version
153-
org.getConnection().getConnectionOptions().accessToken!
154-
}`,
156+
...(skipAuth
157+
? {}
158+
: {
159+
Authorization: `Bearer ${
160+
// we don't care about apiVersion here, just need to get the access token.
161+
// eslint-disable-next-line sf-plugin/get-connection-with-version
162+
org.getConnection().getConnectionOptions().accessToken!
163+
}`,
164+
}),
155165
...headers,
156166
},
157167
body,

0 commit comments

Comments
 (0)