2016-11-28 139 views
0

当我正在尝试从MS图形的一些数据我收到以下错误:微软图形错误InvalidAuthenticationToken

{error: {code: "InvalidAuthenticationToken", message: "Access token validation failure.",…}} 
error:{code: "InvalidAuthenticationToken", message: "Access token validation failure.",…} 
code:"InvalidAuthenticationToken" 
innerError:{request-id: " xxx ", date: "2016-11-28T10:25:52"} 
date : "2016-11-28T10:25:52" 
request-id: " xxx " 
message : "Access token validation failure." 

的应用程序是一个SharePoint外接应阅读Office 365的一些用户和组信息。

我用follwoing代码检索数据:

$.ajax({ 
      type: "GET", 
      url: "https://graph.microsoft.com/v1.0/me/", 
      headers: { 
       'Accept': 'application/json', 
       'Authorization': 'Bearer' + token 
      } 
     }).done(function (response) { 

      console.log(response); 

      //alert(response); 

     }).fail(function() { 
      console.log('Error occurred.'); 
     }); 

对于authenication我用adal.js.登录后()我得到了id_token。当请求发出时,令牌被传递给该函数。

有没有人有同样的问题,可以帮忙吗? 在此先感谢!

+0

我使用了错误的终点在'aquireToken'请求。所以上面的代码是正确的。非常感谢费雪的评论。 –

回答

0

要调用Microsoft Graph REST,我们需要提供访问令牌。客户端使用id_token来验证登录用户。

要获取Microsoft Graph REST的解析访问令牌,我们需要提出两个请求。第一个请求是从授权端点获得授权码。第二个请求是使用从第一个请求获得的代码交换令牌。关于详细请求,你可以参考以下链接:

Microsoft Graph app authentication using Azure AD