Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples on how to use bearer tokens easily #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions docs/scripting/bearer-token-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Bearer token example

If your API requires you to use a bearer token, you might want to use a script like this in the _Post Response_ scripting section:

```javascript
bru.setVar("token", res.body.access_token);
```

With this method, you can then use the `{{token}}` variable in other requests. Just select _Bearer Token_ in the _Auth_ tab and insert your variable.

## String splitting

If the authentication API does not deliver a JSON response but rather a singe string that looks like this `"Bearer FOOBAR"` you might want to split the string with a little something like this:

```javascript
bru.setVar("token", res.body.split(" ")[1]);
```
1 change: 1 addition & 0 deletions docs/table-of-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [External Libraries](/scripting/external-libraries)
- [Sync Requests](/scripting/sync-requests)
- [JavaScript Reference](/scripting/javascript-reference)
- [Bearer token example](/scripting/bearer-token-example)

## Testing

Expand Down