I need programically get user AKS clusters , but
i have problem when execute this request https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/managedClusters?api-version=2018-03-31
Headers : Authorization: bearer {JWT}
I get
{
"error": {
"code": "AuthenticationFailed",
"message": "Authentication failed."
}
}
How i retrieve this JWT token
I use this flow https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#web-application-to-web-api for implementation
grant_type : authorization_code
client_id : {myapp-id}
code : {Retrieve from step 1}
client_secret : {myapp-key}
resource : https://graph.microsoft.com
And in result i has JWT token with payload
{
"aud": "https://graph.microsoft.com",
"iss": "https://sts.windows.net/ee3f07b0-0b4f-4929-acb0-643894a174fa/",
"iat": 1533214682,
"nbf": 1533214682,
"exp": 1533218582,
"acct": 0,
"acr": "1",
"amr": [
"pwd"
],
"app_displayname": "SinglePageApp-jQuery-DotNet",
"appidacr": "1",
"ipaddr": "193.243.159.58",
"name": "Pasha Kostohrys",
"platf": "3",
"puid": "1003BFFDAC20BE5D",
"scp": "Directory.AccessAsUser.All Directory.Read.All Directory.ReadWrite.All Group.Read.All Group.ReadWrite.All Member.Read.Hidden User.Read User.Read.All User.ReadBasic.All",
"ver": "1.0",
"wids": [
"62e90394-69f5-4237-9190-012177145e10"
]
}
The audience of the bearer token you retrieved is https://graph.microsoft.com/
, but the audience of the API you requested is https://management.core.windows.net/
.
I think you should use resource : https://management.core.windows.net/
to get the bearer token, it will work.