0

This is the curl command I'm using which generates a Bearer Token. The command has the following variables: $url(base url), $cid(clientid) and $csec(client secret). I have used the echo command and checked if the variables have stored correct value. If I replace the variables with their stored value then I'm able to fetch the Bearer Token.

curl --request POST $url/oauth/token -d 'grant_type=client_credentials&client_id=$cid&client_secret=$csec'

I'm getting the following error when I run this command:

{"error":"unauthorized","error_description":"Bad credentials"}

I have tried using quotes and braces but still not getting any success. These are the commands I have tried. Please let me know of any alternate approach.

curl --request POST "$url"/oauth/token -d 'grant_type=client_credentials&client_id="$cid"&client_secret="$csec"' curl --request POST '"$url"'/oauth/token -d 'grant_type=client_credentials&client_id='"$cid"'&client_secret='"$csec"'' curl --request POST {$url}/oauth/token -d 'grant_type=client_credentials&client_id={$cid}&client_secret={$csec}'

Saumya
  • 1
  • 2

1 Answers1

0

Use double quotes to enclose a string when you want variables to be expanded (see e.g. Difference between single and double quotes in Bash):

curl --request POST "$url/oauth/token" \
  -d "grant_type=client_credentials&client_id=$cid&client_secret=$csec"
Manfred
  • 2,269
  • 1
  • 5
  • 14