verb-with-jwt.sh

#!/bin/sh
SERVER_URL="${SWGY_SERVER:-http://127.0.0.1}"
# Check if jwt filepath and endpoint parameters are provided
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "Usage: $0 jwt-filepath verb endpoint-url"
    exit 1
fi

# Assign the parameters to variables
jwt_filepath="$1"
verb="$2"
endpoint="$3"

# Read the JWT token from the JSON file
access_token=$(jq -r '.access_token' "$jwt_filepath")
token_type=$(jq -r '.token_type' "$jwt_filepath")

# Check if token_type is "bearer"
if [ "$token_type" != "bearer" ]; then
    echo "Error: invalid token_type"
    exit 1
fi

# Set the Authorization header to the JWT token
authorization="Authorization: Bearer $access_token"

# Send the GET request using curl
url="${SERVER_URL}$endpoint"
curl -k -X $verb -H "$authorization" "$url"