我已经使用Implicit Flow在我的角度应用程序中实现了msal库。我可以使用Microsoft广告帐户登录,并且拥有api使用身份验证请求所需的令牌。当我使用https://jwt.ms/解码令牌时,我可以看到aud密钥的值是我的[[client app id,它的用户信息网址应该看起来像什么?如果我将使用文档中描述的这些端点,则我将使用无效令牌出错:https://graph.microsoft.com/oidc/userinfo或https://graph.microsoft.com/v1.0/me/
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token validation failure. Invalid audience.",
"innerError": {
"request-id": "8177b64f-c899-48c3-aceb-xxxxxxxxx",
"date": "2020-03-18T07:41:04"
}
}
}
获取访问令牌时,应使用https://graph.microsoft.com/User.Read
或仅使用User.Read
作为范围。
此外,请记住在Azure门户上为您的应用程序添加User.Read
权限。应用程序注册->您的应用程序-> API权限->添加权限->选择Microsoft Graph API->委托权限->检查所需的权限。
参考:
MSAL Angular to login, logout, protect a route, and acquire an access token for Microsoft Graph.