refactor(crypto): reorganize token hashing and signing functionality

This commit is contained in:
Danny Avila 2025-05-30 14:38:01 -04:00
parent 6f4c8ef114
commit 494c6d2596
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
10 changed files with 27 additions and 66 deletions

View file

@ -2,12 +2,13 @@ const fetch = require('node-fetch');
const passport = require('passport');
const client = require('openid-client');
const jwtDecode = require('jsonwebtoken/decode');
const { logger } = require('@librechat/data-schemas');
const { CacheKeys } = require('librechat-data-provider');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { hashToken, logger } = require('@librechat/data-schemas');
const { Strategy: OpenIDStrategy } = require('openid-client/passport');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { findUser, createUser, updateUser } = require('~/models');
const { getBalanceConfig } = require('~/server/services/Config');
const getLogStores = require('~/cache/getLogStores');
const { isEnabled } = require('~/server/utils');
@ -36,8 +37,6 @@ class CustomOpenIDStrategy extends OpenIDStrategy {
}
}
const { getBalanceConfig } = require('~/server/services/Config');
let crypto;
let webcrypto;
try {
@ -47,12 +46,6 @@ try {
logger.error('[openidStrategy] crypto support is disabled!', err);
}
async function hashToken(str) {
const data = new TextEncoder().encode(str);
const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
return Buffer.from(hashBuffer).toString('hex');
}
/**
* Exchange the access token for a new access token using the on-behalf-of flow if required.
* @param {Configuration} config