Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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}&resource=https%3A%2F%2Fmanagement.azure.com%2F' \
            https://login.microsoftonline.com/${tenant_id}/oauth2/token | jq -r '.access_token')

The value of TOKEN is always null.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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**&resource=https%3A%2F%2Fmanagement.azure.com%2F' \
            https://login.microsoftonline.com/${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}&resource=https%3A%2F%2Fmanagement.azure.com%2F’

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}&resource=https%3A%2F%2Fmanagement.azure.com%2F"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading