【发布时间】:2017-02-09 18:52:24
【问题描述】:
我正在构建一个页面,其中包含多次调用 Microsoft Graph 到不同端点:获取 OneDrive 文件、电子邮件、用户属性等。
一个不起作用的调用是获取当前用户的日历事件。我使用的终点是https://graph.microsoft.com/v1.0/me/events。响应是 403 Forbidden。
根据 Microsoft 文档 here,应用程序需要 Calendars.Read 或 Calendars.ReadWrite 权限。我在 delegated 权限下检查了这两个,但仍然是同样的问题。然后我在 Azure AD 中为这个应用勾选了所有 51 个权限范围,但仍然是同样的问题。
我也尝试在 Azure AD 中创建一个新应用,但这没有帮助。
如何使用 Microsoft Graph 取回当前用户的日历活动?我错过了什么?
编辑:
我正在使用 ADAL.js 进行身份验证。这是我在自己的 doAuth 函数中的代码,它接收应用程序的客户端 ID。
function doAuth(clientId) {
var variables = {
// Domain of Azure AD tenant
azureAD: // the appropriate URL,
// ClientId of Azure AD application principal
clientId: clientId,
// Name of SharePoint tenant
sharePointTenant: // the appropriate URL
}
// Create config and get AuthenticationContext
window.config = {
tenant: variables.azureAD,
clientId: variables.clientId,
postLogoutRedirectUri: window.location.origin,
endpoints: {
graphApiUri: "https://graph.microsoft.com",
sharePointUri: "https://" + variables.sharePointTenant + ".sharepoint.com",
},
cacheLocation: "localStorage"
}
var authContext = new AuthenticationContext(config);
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
var user = authContext.getCachedUser();
var token = authContext.getCachedToken(clientId);
if (!user || !token)
authContext.login();
return authContext
}
【问题讨论】:
-
您是否检查过从 login.microsoftonline.com 返回的 JWT 令牌是否包含所需的范围?
-
@RasmusW 你能解释一下我如何检查令牌的范围吗?我需要在
AuthenticationContext对象上使用一种方法吗? -
我的意思是手动操作。您可以获取 jwt.io 或 jwt.calebb.net 等网站来为您解码。如果它们是标准 JWT,最后一个甚至包含有关每个属性的一些文档。
-
我已将我的 ADAL 代码添加到我的问题中。如何检查从 login.microsoftonline.com 返回的 JSON 对象?
标签: javascript jquery calendar office365 microsoft-graph-api