mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 19:00:13 +01:00
refactor(crypto): reorganize token hashing and signing functionality
This commit is contained in:
parent
6f4c8ef114
commit
494c6d2596
10 changed files with 27 additions and 66 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue