Javascript 接收到来自adal.js的无效令牌
我正在尝试创建一个小的客户端webapp,目前没有角度部分 我已成功登录并获得经过身份验证的用户对象。然而,我从API中得到了一个无效的OAuth令牌 我要发送到AuthenticationContext实例的配置:Javascript 接收到来自adal.js的无效令牌,javascript,azure,oauth,azure-active-directory,adal,Javascript,Azure,Oauth,Azure Active Directory,Adal,我正在尝试创建一个小的客户端webapp,目前没有角度部分 我已成功登录并获得经过身份验证的用户对象。然而,我从API中得到了一个无效的OAuth令牌 我要发送到AuthenticationContext实例的配置: var config = { instance: 'https://login.microsoftonline.com/', tenant: 'dbaa88b3-...', clientId: 'f81bede8-...', postLogoutRe
var config = {
instance: 'https://login.microsoftonline.com/',
tenant: 'dbaa88b3-...',
clientId: 'f81bede8-...',
postLogoutRedirectUri: window.location.href,
cacheLocation: 'localStorage',
};
不确定是租户ID还是租户名称
那么当我通过身份验证时,我正在使用
var context = new AuthenticationContext(config);
context.acquireToken(context.config.clientId, function(error, token) {
// error is null
var now = new Date();
$.ajax({
url: "https://outlook.office365.com/api/v1.0/me/calendarview",
method: "GET",
data: {
"startdatetime": (new Date()).toISOString(),
"enddatetime": (new Date()).toISOString()
},
headers: {
"Authorization": "Bearer " + token,
"Accept": "application/json; odata.metadata=full",
"Client-Request-Id": clientid, // Some unique machine id?
"User-Agent": navigator.userAgent,
"Date": now.toUTCString()
}
}).then(function(result) {},
function(e) {
console.error(e);
// 401 response, x-ms-diagnostics header = 2000005;reason="The PUID value was not found for [ORGID] identity.";error_category="invalid_user"
});
});
如果我手动输入使用同一帐户生成的身份验证令牌成功。tl;如果需要访问令牌,dr不会将客户端id作为第一个参数发送到acquireToken
好像我用错图书馆了
调用acquireToken时,如果您想要访问令牌,则不应提供clientId作为第一个参数,然后您将获得标识令牌。您可以使用该工具解决此问题,谢谢@rich randall。至少我是这样理解这个问题的
因此,我向API提供了标识,而不是访问令牌,因为API不包含puid值,因此出现了错误消息:
// 401 response, x-ms-diagnostics header = 2000005;reason="The PUID value was not found for [ORGID] identity.";error_category="invalid_user"
现在我可以从API中提取数据了。您可以使用此站点解码这两个令牌并进行比较:如果不是clientId,那么需要传递什么。让它为空不起作用。请将完整的解决方案首尾相连地发布。获取调用图api的有效令牌时存在多个问题