【发布时间】:2015-05-29 13:36:44
【问题描述】:
我正在尝试使用adal.js(目前没有角度部分)创建一个小型客户端 web 应用程序。
我已经成功登录并获得了一个经过身份验证的用户对象。但是,我显然从 API 获得了无效的 OAuth 令牌。
我发送到 AuthenticationContext 实例的配置:
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"
});
});
如果我在https://oauthplay.azurewebsites.net/ 上手动输入使用相同帐户生成的身份验证令牌,它会成功。
【问题讨论】:
-
你能用这个网站来解码这两个令牌并比较:jwt.io
标签: javascript azure oauth azure-active-directory adal