【发布时间】:2017-09-14 13:49:03
【问题描述】:
我正在将 Microsoft Graph API 添加到应用程序,但 Get 无法正常工作。我什至不确定它是否发送请求。我得到的 URL 来自 Microsoft Graph Explorer。
我能够通过 ADAL 正确地进行身份验证,并取回令牌。代码如下:
import {Http, Headers} from "@angular/http";
import {Injectable} from "@angular/core";
//import 'rxjs/add/operator/map'
//import 'rxjs/add/operator/catch'
import 'rxjs/Rx';
@Injectable()
export class EmailRESTService {
data: any;
token = localStorage.getItem("token");
constructor(private http: Http) {
this.data = null;
}
load() {
console.log('Inside EmailREST Promise: ');
this.http.get('https://graph.microsoft.com/v1.0/me', {
headers: new Headers ({"Authorization": "Bearer " + this.token})
}).subscribe(data => {
if(data.status == 200){
this.data = data.json();
}
if(data.status!= 200){
console.log('SOmething worng in Subscribe');
}
});
}
}
我得到这个输出:
console.log('Inside EmailREST Promise: ');
但之后没有输出。我从网上尝试了许多建议/代码,但没有成功。
这是在错误的 API 端点(Azure Graph API 与 Graph API)上使用 ADAL Auth 的问题吗?我尝试使用此网址: https://graph.windows.net/me?api-version 对于 Azure Graph API 没有成功
提前致谢。
【问题讨论】:
-
令牌中的
aud和scp声明是什么?您可以解码来自here 的令牌和令牌中的声明。 -
@FeiXue "aud":"graph.windows.net" & "scp": "User.Read"
-
你应该写一个错误处理程序,订阅函数的第二个参数。将该错误记录到控制台。或者,您可以检查网络选项卡以查看呼叫失败的原因
-
我觉得你还需要发送 Content-Type header
-
看起来您可能正在混合和匹配 AAD Graph 和 Microsoft Graph - 但它们是不同的。如果您正在调用 Microsoft Graph,则需要获取具有
https://graph.microsoft.com受众 (aud) 的令牌。您在评论回复中拥有的是 AAD Graph 的受众。
标签: angular ionic2 microsoft-graph-api azure-ad-graph-api