Skip to content

Commit 43c6e24

Browse files
authoredMay 29, 2024
Merge pull request #256 from fflores97/auth-commandline
Expand documentation on external-tool auth
2 parents dc11c79 + 1c28743 commit 43c6e24

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed
 

‎docs/configuration.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,36 @@ helper commandline:
333333
"method": "GET",
334334
"uri": "http://...",
335335
"headers": {
336-
"content-type": [""]
336+
"content-type": [""],
337+
"authorization": ["Bearer <YOUR_TOKEN_HERE>"]
337338
// …
338339
},
339340
"body": ""
340341
}
341342
```
342-
343-
The same shape is expected on the program's standard output. Two
343+
The same shape is expected on the program's standard output. Please note that the fields inside `headers` must be in an array. Two
344344
parameters only will be considered:
345345

346346
- `headers`: Values present will be added to the outbound payload.
347-
- `uri`: Will replace the destination URL entirely (allowing the
348-
addition of query arguments if needed).
347+
- `uri`: Will replace the destination URL entirely (allowing the addition of query arguments if needed).
348+
349+
Here is a good example of how to use this versatile option. Suppose you've written a script in your favorite language that connects to an Auth server and writes a relatively standard OAuth 2.0 JSON in the following shape:
350+
351+
```json
352+
{
353+
"expires_in": 3600,
354+
"access_token": "<access_token>",
355+
"refresh_token": "<refresh_token>",
356+
"scope": "<scopes>"
357+
}
358+
```
359+
You might find yourself doing this with a lot of APIs because not everyone follows the same OAuth 2.0 conventions (maybe you used `restish` to get this token manually in the first place!). Then, when you need to use this file, you could write a quick one-liner with `jq` to convert this to the appropriate format and feed it into `restish` with a line like this in your `commandline`:
360+
361+
```bash
362+
jq '{headers: {authorization: ["Bearer " + .access_token]}}' /path/to/auth_token.json
363+
```
364+
365+
As long as your input writes the appropriate format to the standard output (**very important**), `restish` will modify the outgoing request accordingly.
349366

350367
### Loading from files or URLs
351368

0 commit comments

Comments
 (0)