我正在开发 Outlook Web 加载项。
我正在尝试通过库验证我传递给服务器端的令牌node.js
,但它失败了,我不明白为什么。
这就是我为检索用户身份令牌所做的工作。
Office.context.mailbox.getUserIdentityTokenAsync(function(result) {
result.value // contains the token.
// send this value to server side, which I can see that it's working.
})
在服务器端,我检索令牌并执行以下操作:
token; // contains the token passed from the web-app.
const jwt = require('jsonwebtoken');
const request = require('request');
let decoded = jwt.decode(token, {complete: true});
// Get the key, we'll need this later since we'll have to
// find the matching key from the config file.
let key = decoded.header.x5t;
let amurl = JSON.parse(decoded.payload.appctx).amurl;
// Make a request to the url to get the configuration json file.
request(amurl, {}, (err, response, body) => {
let keys = JSON.parse(body).keys;
// Filter the keys so we get the one which we can verify.
let s = keys.filter(t => t.keyinfo.x5t === key);
let cert = s[0].keyvalue.value;
// Fails the verification.
console.log(jwt.verify(token, cert));
});
澄清一下,我正在正确检索令牌,并且这个 npm 包似乎对其他 jwt 令牌运行良好。(所以这不是真正的配置问题)