简体   繁体   中英

PowerShellLibJava is fetching invalid JSON token from java code in docker container

I am using PowerShellLibJava ( https://github.com/Tuupertunut/PowerShellLibJava ) in java code to fetch access token from azure. Earlier it was working fine in docker container. On windows machine, its working fine but when fetching in docker container it's providing invalid access token (binary content instead of JSON)

To login using command

az login --allow-no-subscriptions -u <emailAddress> -p <password>

login successfully.

using this command through "executeCommands" to fetch token

az account get-access-token --resource-type ms-graph

groovy script and shell both are able to fetch valid access token in container but java code is failing to fetch the token.

Fetching in a docker container it's providing an invalid access token (binary content instead of JSON)

The error shows that you are not converting the JSON while getting the Access Token .

1. Using AZ-CLI

you can convert the Access token from JSON.

# Get Access Token
az  account  get-access-token  --resource  ms-graph  |  ConvertFrom-Json

2. Using PowerShell

You can use the Get-AzAccessToken to get the Access Token of ms-graph

# Get Access Token
$graphToken =Get-AzAccessToken -ResourceTypeName MSGraph

Reference

Compare get-access-token and Get-AzAccessToken

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM