作者:西安黄河文化补习学校 | 来源:互联网 | 2022-12-02 16:57
我将在Angular Web应用程序中使用Microsoft Graph API。
首先,我使用msal库进行连接。
当我尝试使用配置文件登录时,出现此错误
我已经按照官方git示例中提到的配置了我的应用
MsalModule.forRoot({
clientID: "Tenant ID",
authority: "https://login.microsoftonline.com/common/",
redirectUri: "http://localhost:4200/",
validateAuthority : true,
popUp: true
}),
身份验证正在进行,我得到了令牌。
然后,当我进入主页时,我再次向Microsoft Graph API发出请求,以使用该令牌获取用户信息。
getProfile() {
let header= new Headers();
let tokenid= sessionStorage.getItem('msal.idtoken');
header.set('Authorization', 'Bearer ' + tokenid)
let url ="https://graph.microsoft.com/v1.0/me/"
return this.http.get(url,{headers:header});
}
}
我收到响应401 Unauthorized错误:
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token validation failure.",
"innerError": {
"request-id": "xxxxxx",
"date": "2018-10-09T22:58:41"
}
}
}
我不知道为什么MG API不接受我的令牌,我是否使用了错误的授权URL?
更新:我知道实际上我得到的id_token与访问令牌不同。如何从MSAL库获取Access令牌以进行MS GRAPH API调用?: