1

当使用 Postman 在 Chrome 和x-zumo-authheader 中进行身份验证时,我的 API 应用程序使用控制器中的以下代码成功识别了用户的 upn:

Runtime runtime = Runtime.FromAppSettings(Request);
EmaUserInfo user = runtime.CurrentUser;
TokenResult token = await user.GetRawTokenAsync("aad");
string upn = token.Claims[ClaimTypes.Upn];

但是,当使用 Microsoft 的AzureCards控制台客户端示例中的代码(将浏览器添加到表单窗口并捕获 zumo 令牌)时,我无法获取用户的 aad 令牌并从 API 应用程序中获得以下错误:

Request to https://[gateway].azurewebsites.net/api/tokens?tokenName=aad&api-version=2015-01-14 GET failed BadRequest 400 (Bad Request)
{
  "status": 400,
  "source": "https://[gateway].azurewebsites.net/api/tokens?tokenName=aad&api-version=2015-01-14",
  "message": "Microservice '[API App]' only has permissions for token ''. Can't get token 'aad'"
}

有趣的是,当我设置断点并将 zumo 令牌从我的测试程序复制到邮递员时,甚至会发生这种情况。程序失败,邮递员成功返回。据我所知,他们发送的请求完全相同。我会错过什么?

编辑:我做了更多测试,发现 Postman 方法在隐身模式下会产生相同的错误。这让我相信不仅x-zumo-auth需要设置标头,还需要设置一些 cookie 以使用户正常工作。如果我生成令牌,从 apiapp url 中删除 cookie 并仅使用令牌发布请求,我也会收到错误消息。

4

1 回答 1

6

API 应用程序应该有一个:authentication" 数组,它看起来像这样:

"authentication": [{"type": "aad"}]

你最终的 apiapp.json 应该是这样的:

{
"$schema": "http://json-schema.org/schemas/2014-11-01/apiapp.json#",
"id": "YourApiApps",
"namespace": "microsoft.com",
"gateway": "2015-01-14",
"version": "1.0.0",
"title": "YourApiApps",
"summary": "",
"author": "",
"endpoints": {
    "apiDefinition": "/swagger/docs/v1",
    "status": null
},
"authentication": [{"type": "aad"}]}

然后,请重新部署并再次检查。它应该解决问题。

于 2015-05-29T18:50:59.023 回答