Skip to content

Commit

Permalink
Change cURL config filename
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Mar 22, 2021
1 parent 4430d31 commit e64f8a9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docs/api/Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ All API calls require an access token. You can get an access token by making a P
!!! warning
It is **strongly** recomended to store and retrieve your login credentials in a [cURL config file](https://everything.curl.dev/cmdline/configfile) that only your user can read to avoid exposing your credentials to your shell history or the host process table.

Create a cURL config file named `wq2_login`:
Create a cURL config file named `wq2_login.config`:
```bash
nano ~/wq_login
nano ~/wq_login.config
```

Add the cURL options:
```python
# ~/wq_login
# ~/wq_login.config
request = POST
header = "Content-Type: application/json"
data = {"username":"USERNAME","password":"PASSWORD"}
Expand All @@ -49,17 +49,21 @@ All API calls require an access token. You can get an access token by making a P

Restrict read permissions to your user:
```bash
chmod 700 ~/wq_login
chmod 700 ~/wq_login.config
```

Run cURL using your new config file:
```bash
curl -K ~/wq_login
curl -K ~/wq_login.config
```
```
# Expected Output:
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MTYxODI1MjMsIm5iZiI6MTYxNjE4MjUyMywianRpIjoiYzI2ZjY4NDctZGU2OC00ODUzLWI4ODctMTBmZDAyMDcyY2U0IiwiZXhwIjoxNjE2MTgzNDIzLCJzdWIiOiJjYW1wYjMwMyIsImZyZXNoIjpmYWxzZSwidHlwZSI6ImFjY2VzcyIsImNzcmYiOiJjYjYzZWE1My1jOWQ2LTQ5YTItYmZhMi0wY2U4N2Q3YzcxZDcifQ.T7bezsOMreMCXWR0R5w5BKI673hpOquCOnvT1XkyDjY"}
```

??? tip "Tip for Parsing Tokens in Bash"
You can parse the access token using Python like this:
```bash
curl -K ~/wq_login | \
curl -K ~/wq_login.config | \
python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])"
```

0 comments on commit e64f8a9

Please sign in to comment.