Azure AD App Service /.auth/refresh端点返回401.71未经授权

时间:2017-02-28 21:46:01

标签: azure-web-sites azure-active-directory

我正在使用带有vanilla MVC 5 Web应用程序的Azure AD测试Azure应用服务身份验证/授权。我已按照https://cgillum.tech/2016/03/07/app-service-token-store/http://cgillum.tech/2016/03/25/app-service-auth-aad-graph-api/

上的教程进行操作

我可以确认/.auth/me端点是否正常运行,并且我确实在缓存中有刷新和访问令牌。

应用程序注册配置了SharePoint Online权限。

然而,/。auth / refresh失败,每次都未经授权401.71。 Web应用程序上的详细日志流仅提供一般错误消息。

我在各种论坛的评论部分看到了对aa值的引用:“access_type = offline”,这可能是也可能不需要包含在authsettings中的“additionalLoginParams”键中,尽管它通常在上下文中提到谷歌授权。

在使用AAD时是否需要添加是否有明确的答案?教程中没有提到的任何其他权限?

这是我用来进行测试的代码

 string endpoint = myAppUrl + "/.auth/refresh";

 string idToken = this.Request.Headers["X-MS-TOKEN-AAD-ID-TOKEN"];
 string accessToken = this.Request.Headers["X-MS-TOKEN-AAD-ACCESS-TOKEN"];
 string refreshToken = this.Request.Headers["X-MS-TOKEN-AAD-REFRESH-TOKEN"];

 using (HttpClient client = new HttpClient())
 {
     try
     {
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
         HttpResponseMessage response = client.GetAsync(endpoint).Result;
         if (response.IsSuccessStatusCode)
         {
             string content = response.Content.ReadAsStringAsync().Result;
         }
     }
     catch (Exception oops)
     {
         string oopsMessage = oops.Message;
     }
 }

1 个答案:

答案 0 :(得分:1)

问题是/.auth/refresh API不适用于AAD承载令牌。相反,您需要使用会话cookie( AppServiceAuthSession cookie)或会话令牌( x-zumo-auth 标头),它们是登录操作的输出。

很抱歉给您带来不便,并且缺少明确的错误信息。我们将在未来的版本中考虑增加对此的支持。