Outlook REST API:V1IDToken不适用于当前协议
我正在尝试通过Javascript从Outlook帐户检索我的电子邮件。 我使用ADAL对自己进行身份验证,这似乎有效。但是,如果我尝试在对outlook REST API的GET请求中使用返回的令牌,我会返回未经授权的错误,并在标头中显示以下附加信息:Outlook REST API:V1IDToken不适用于当前协议,rest,outlook,adal,Rest,Outlook,Adal,我正在尝试通过Javascript从Outlook帐户检索我的电子邮件。 我使用ADAL对自己进行身份验证,这似乎有效。但是,如果我尝试在对outlook REST API的GET请求中使用返回的令牌,我会返回未经授权的错误,并在标头中显示以下附加信息: x-ms-diagnostics:2000001;原因=“此令牌配置文件“V1IdToken”不适用于当前协议。”;错误\u category=“无效\u令牌” 我的请求如下: function test2(token) { tr
x-ms-diagnostics:2000001;原因=“此令牌配置文件“V1IdToken”不适用于当前协议。”;错误\u category=“无效\u令牌”
我的请求如下:
function test2(token) {
try
{
var xhr = new XMLHttpRequest();
xhr.open("GET", 'https://outlook.office.com/api/v1.0/me/messages');
// The APIs require an OAuth access token in the Authorization header, formatted like this: 'Authorization: Bearer <token>'.
xhr.setRequestHeader("Authorization", "Bearer " + token);
// Process the response from the API.
xhr.onload = function () {
// ...
}
// Make request.
xhr.send();
函数test2(令牌){
尝试
{
var xhr=new XMLHttpRequest();
xhr.open(“GET”https://outlook.office.com/api/v1.0/me/messages');
//这些API需要授权头中的OAuth访问令牌,格式如下:“Authorization:Bearer”。
xhr.setRequestHeader(“授权”、“承载人”+令牌);
//处理来自API的响应。
xhr.onload=函数(){
// ...
}
//提出请求。
xhr.send();
我尝试了v1.0和v2.0 REST api。根据错误消息,您使用id\u令牌请求Outlook online REST。id\u令牌仅用于客户端验证用户身份。要请求Outlook online REST,我们需要使用访问令牌 如果您使用angularJS进行开发,则无需手动附加令牌。以下是代码示例供您参考:
你好{{userInfo.userName}
- 获取消息
- 注销
- 登录
{{item.Subject}}
{{item.Sender.EmailAddress.Address}
var myApp=angular.module('myApp',['AdalAngular']))
.config(['$httpProvider','adalAuthenticationServiceProvider',函数($httpProvider,adalProvider){
变量端点={
"https://outlook.office.com": "https://outlook.office.com",
};
adalProvider.init(
{
实例:'https://login.microsoftonline.com/',
租户:“{yourtanent}.onmicrosoft.com”,
clientId:“{yourAppId}”,
extraQueryParameter:'nux=1',
端点:端点,
},
$httpProvider
);
}])
myApp.controller('homeCtrl'、['$scope'、'$http'、'adalAuthenticationService'、'$location'、'toGetMessagesSvc',函数($scope、$http、adalService、$location、toGetMessagesSvc){
$scope.login=函数(){
adalService.login();
};
$scope.logout=函数(){
adalService.logOut();
};
$scope.getMessages=函数(){
toGetMessagesSvc.getMessages().success(函数(结果){
$scope.messages=results.value;
$scope.loadingMessage=“”;
});
}
}]);
myApp.factory('toGetMessagesSvc',['$http',函数($http){
var apidentpoint=”https://outlook.office.com/";
$http.defaults.useXDomain=true;
删除$http.defaults.headers.common['X-Requested-With'];
返回{
getMessages:函数(){
返回$http.get(apidentpoint+'api/v1.0/me/messages');
}
};
}]);
如果答案有帮助,请告诉我。