This commit is contained in:
aozhiwei 2024-05-31 17:32:23 +08:00
parent 1907b7a54f
commit 36993cf342
2 changed files with 29 additions and 0 deletions

View File

@ -1,7 +1,32 @@
const app = require('j7/app');
const base64url = require('base64url');
const jwksClient = require('jwks-rsa');
const jwt = require('jsonwebtoken');
async function verify(session) {
const postData = session.getBody();
console.log(postData);
const jwksUri = postData['jwksUri'];
const arr = postData['data'].split('.');
const header = base64url.decode(arr[0]);
const payload = base64url.decode(arr[1]);
const sign = base64url.decode(arr[2]);
const client = jwksClient({
jwksUri: jwksUri
});
function getKey(header, cb ) {
console.log(header);
client.getSigningKey(header.kid, function(err, key) {
console.log(err);
console.log(key);
const signingKey = key.publicKey || key.rsaPublicKey;
cb(null, signingKey);
});
};
jwt.verify(postData['data'], getKey, function(err, decoded) {
console.log(err);
console.log(decoded);
});
}
function init() {

View File

@ -65,6 +65,10 @@ class Session {
return utils.jsonEncode(this.req.query);
}
getBody() {
return this.req.body;
}
async getBcEventDb() {
const idx = 0;
const dbKey = 'BcEventDb' + idx;