사용자 액세스 토큰 (JWT)의 유효성을 검사하는 미들웨어 기능을 구축했습니다 .JWT가 만료 된 경우 사용자의 새로 고침 토큰에서 새 액세스 토큰을 자동으로 만듭니다 (물론 유효한 경우).
어느 시점에서 충분한 사용자가 있으면 권한 부여가 병목이 될 수 있다고 생각합니다. 이러한 함수가 비동기 적으로 실행되는지 확인하고 싶습니다 (예 : UV 스레드 풀을 통해).
이것이 가능합니까, 아니면 이것에 대해 걱정해야합니까?
추가:
이것은 미들웨어 기능에서 사용하는 암호 해독 루틴입니다. 나는 또한 jsonwebtoken을 사용하고 있습니다.
'use strict';
const cryptoAsync = require('@ronomon/crypto-async');
const crypto = require('crypto');
const util = require('util');
class AES {
constructor(key, iv, bitSize) {
// supported stream ciphers:
// aes-256-ctr (keySize=32, ivSize=16)
// aes-192-ctr (keySize=24, ivSize=16)
// aes-128-ctr (keySize=16, ivSize=16)
if (!bitSize) bitSize = 128;
if (bitSize !== 256 && bitSize !== 192 && bitSize !== 128) {
throw new Error('AES requires a bitsize of 256, 192, or 128.');
}
if (!key || key.length !== bitSize/8) throw new Error(`A ${bitSize/8}-byte/${bitSize}-bit key is required.`);
if (!iv || iv.length !== 16) throw new Error('A 16-byte/128-bit initialization vector is required.');
this.algo = `aes-${bitSize}-ctr`;
this.key = key;
this.iv = iv;
console.log(`Using the ${this.algo} algorithm ...`);
}
async encrypt(dataAsUtf8) {
const cipherText = await util.promisify(cryptoAsync.cipher)(this.algo, 1, this.key, this.iv, Buffer.from(dataAsUtf8, 'utf8'));
return cipherText.toString('hex');
}
async decrypt(dataAsHex) {
if (!Buffer.isEncoding('hex')) throw new Error('Input must be in HEX format.');
const cipherText = await util.promisify(cryptoAsync.cipher)(this.algo, 0, this.key, this.iv, Buffer.from(dataAsHex, 'hex'));
return cipherText.toString('utf8');
}
static randomBytes = async bytes => {
const bytesAsBuffer = await util.promisify(crypto.randomBytes)(bytes);
return bytesAsBuffer;
}
}
module.exports = AES;
매우 큰 보고서를 생성하는 것과 같은 심각한 작업을 수행하지 않는 한 상당한 시간 동안 Node에서 메인 스레드를 차단하는 코드를 작성하는 것은 실제로 매우 어렵습니다. JWT 토큰을 통한 인증은 완전히 가볍고 문제가되지 않습니다. 사실상 보장 할 수 있습니다. 그게 계획이라면 해당 유형의 작업을 별도의 스레드로 밀어 넣을 필요가 없습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다