Created
February 17, 2022 12:00
-
-
Save malkab/0551a9b6316c2b85b78de6b9c8f80039 to your computer and use it in GitHub Desktop.
cURL: Accessing a Bearer Token Auth Service with bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ---------------- | |
# | |
# Authorizes an user, retrieves the Bearer token and calls a securized | |
# API entry. | |
# | |
# ---------------- | |
# Auth credentials | |
API_USER=the_user | |
API_PASS=the_pass | |
echo | |
# Gets the token. This retrieves a JSON like this | |
# | |
# { success: { accessToken: "XXXXX" } } | |
# | |
# that is parsed with jq to retrieve the token. | |
TOKEN=$(curl -k -X POST \ | |
-d "user=${API_USER}&pass=${API_PASS}" \ | |
https://whatever.com/auth/login | jq -r ".success.accessToken") | |
echo | |
curl -k -H "Authorization: Bearer ${TOKEN}" \ | |
https://whatever.com/securized --output result.json | |
echo | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment