azure-devopsmicrosoft-fabric

Unable to print access token for Fabric REST API in ADO


While trying to generate access token for calling (Git - Update From Git) API, i am running the powershell script in release pipeline storing the secrets in variables. I am getting below error where the token generated appears to be encrypted. I am not sure if its generating the correct token value.

Error:

2025-03-04T16:05:53.2823941Z Access Token: ***

Script:

# Define Variables
$scope = "https://api.fabric.microsoft.com/.default"
$tokenUrl = "https://login.microsoftonline.com/**/oauth2/v2.0/token"


# Prompt for user credentials 
$authParams = @{
    "client_id"    = $env:clientId
    "scope"        = "https://api.fabric.microsoft.com/.default"
    "grant_type"   = "client_credentials"
    "client_secret"     = $env:client_secret
}

# Get Access Token
$response = Invoke-RestMethod -Method Post -Uri $tokenUrl -ContentType "application/x-www-form-urlencoded" -Body $authParams

# Extract and Output the Token
$accessToken = $response.access_token
Write-Output "Access Token: $accessToken"

Solution

  • This is a correct behavior that the values of secrets (such password, PAT, access token, or other privacy information) will be masked as '***' in the output logs when trying to print the secret values in pipelines.

    Azure Pipelines makes an effort to mask secrets when emitting data to pipeline logs, so you may see additional variables and data masked in output and logs that are not set as secrets. enter image description here

    It is strongly recommended that:

    Never echo secrets as output. Some operating systems log command line arguments. Never pass secrets on the command line. enter image description here

    For more details, see "Set secret variables".


    For your case, if you want to check whether the PowerShell script can generate a valid access token, you can test it on your local machine. After confirming the script can generate the valid access token, you can move it to the Azure DevOps pipeline for use.