Using variables to obtain TOKEN via Azure CLI

I am currently trying to get a Token for Authenticating towards Azure API via Github workflow bash step.
The values of the two variables are coming from Azure Keyvault and thats why i need to pass them in form of variables.

The command that i am using is the following:

- run: |

TOKEN=$(curl -X POST \
            -d 'grant_type=client_credentials&client_id=${user}&client_secret=${password}&' \
  ${tenant_id}/oauth2/token | jq -r '.access_token')

The value of TOKEN is always null.

If i try the same command, but use the values instead of variables ${user} and ${password} the token is created.

TOKEN=$(curl -X POST \
            -d 'grant_type=client_credentials&client_id=**MYUSER**&client_secret=**MYPASSWORD**&' \
  ${tenant_id}/oauth2/token | jq -r '.access_token')

Interesting is that only the 2 variables ${user} and ${password} are not being picked up, the variable for {tenant_id} works.

Why i cannot use the variables inside of grant_type=client_credentials&client_id=${user}&client_secret=${password}&’

This works in Azure Devops Pipeline , but not in Github Workflows

>Solution :

Use double quotes instead of single quotes, else var substitution doesnt happen "grant_type=client_credentials&client_id=${user}&client_secret=${password}&"

Leave a Reply