Azure AKS群集API身份验证失败错误

时间:2018-08-02 13:39:09

标签: azure azure-api-management azure-kubernetes

我需要以编程方式获取用户AKS集群,但是

执行此请求时遇到问题 https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/managedClusters?api-version=2018-03-31

标题: 授权:承载{JWT}

我知道

{
    "error": {
        "code": "AuthenticationFailed",
        "message": "Authentication failed."
    }
}

我如何检索此JWT令牌

我使用此流程https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#web-application-to-web-api进行实施

  1. 我将其https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-openid-connect-code用于获取代码
  2. 我尝试检索访问令牌后 https://login.microsoftonline.com/{tenant-id}/oauth2/token 标头:

grant_type:授权码
client_id:{myapp-id}
代码:{从步骤1检索}
client_secret:{myapp-key}
资源:https://graph.microsoft.com

结果是我有带有有效负载的JWT令牌

{
  "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"
  ]
}

1 个答案:

答案 0 :(得分:0)

您检索到的承载令牌的受众是https://graph.microsoft.com/,但是您请求的API的受众是https://management.core.windows.net/

我认为您应该使用resource : https://management.core.windows.net/来获得不记名令牌,它将起作用。