mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🕸️ refactor: Migrate from crypto to Web Crypto API (#3357)
* move crypto to async webcrypto update encrypt/decrypt forgot await * chore: import order - openidStrategy.js * chore: import order - Session.js * chore: import order - AuthController.js * Update AuthService.js --------- Co-authored-by: Danny Avila <danacordially@gmail.com>
This commit is contained in:
parent
b6fe7e5570
commit
3e0f95458f
10 changed files with 108 additions and 51 deletions
|
|
@ -116,8 +116,8 @@ async function loadActionSets(searchParams) {
|
|||
* @param {ActionRequest} params.requestBuilder - The ActionRequest builder class to execute the API call.
|
||||
* @returns { { _call: (toolInput: Object) => unknown} } An object with `_call` method to execute the tool input.
|
||||
*/
|
||||
function createActionTool({ action, requestBuilder }) {
|
||||
action.metadata = decryptMetadata(action.metadata);
|
||||
async function createActionTool({ action, requestBuilder }) {
|
||||
action.metadata = await decryptMetadata(action.metadata);
|
||||
const _call = async (toolInput) => {
|
||||
try {
|
||||
requestBuilder.setParams(toolInput);
|
||||
|
|
@ -153,23 +153,23 @@ function createActionTool({ action, requestBuilder }) {
|
|||
* @param {ActionMetadata} metadata - The action metadata to encrypt.
|
||||
* @returns {ActionMetadata} The updated action metadata with encrypted values.
|
||||
*/
|
||||
function encryptMetadata(metadata) {
|
||||
async function encryptMetadata(metadata) {
|
||||
const encryptedMetadata = { ...metadata };
|
||||
|
||||
// ServiceHttp
|
||||
if (metadata.auth && metadata.auth.type === AuthTypeEnum.ServiceHttp) {
|
||||
if (metadata.api_key) {
|
||||
encryptedMetadata.api_key = encryptV2(metadata.api_key);
|
||||
encryptedMetadata.api_key = await encryptV2(metadata.api_key);
|
||||
}
|
||||
}
|
||||
|
||||
// OAuth
|
||||
else if (metadata.auth && metadata.auth.type === AuthTypeEnum.OAuth) {
|
||||
if (metadata.oauth_client_id) {
|
||||
encryptedMetadata.oauth_client_id = encryptV2(metadata.oauth_client_id);
|
||||
encryptedMetadata.oauth_client_id = await encryptV2(metadata.oauth_client_id);
|
||||
}
|
||||
if (metadata.oauth_client_secret) {
|
||||
encryptedMetadata.oauth_client_secret = encryptV2(metadata.oauth_client_secret);
|
||||
encryptedMetadata.oauth_client_secret = await encryptV2(metadata.oauth_client_secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,23 +182,23 @@ function encryptMetadata(metadata) {
|
|||
* @param {ActionMetadata} metadata - The action metadata to decrypt.
|
||||
* @returns {ActionMetadata} The updated action metadata with decrypted values.
|
||||
*/
|
||||
function decryptMetadata(metadata) {
|
||||
async function decryptMetadata(metadata) {
|
||||
const decryptedMetadata = { ...metadata };
|
||||
|
||||
// ServiceHttp
|
||||
if (metadata.auth && metadata.auth.type === AuthTypeEnum.ServiceHttp) {
|
||||
if (metadata.api_key) {
|
||||
decryptedMetadata.api_key = decryptV2(metadata.api_key);
|
||||
decryptedMetadata.api_key = await decryptV2(metadata.api_key);
|
||||
}
|
||||
}
|
||||
|
||||
// OAuth
|
||||
else if (metadata.auth && metadata.auth.type === AuthTypeEnum.OAuth) {
|
||||
if (metadata.oauth_client_id) {
|
||||
decryptedMetadata.oauth_client_id = decryptV2(metadata.oauth_client_id);
|
||||
decryptedMetadata.oauth_client_id = await decryptV2(metadata.oauth_client_id);
|
||||
}
|
||||
if (metadata.oauth_client_secret) {
|
||||
decryptedMetadata.oauth_client_secret = decryptV2(metadata.oauth_client_secret);
|
||||
decryptedMetadata.oauth_client_secret = await decryptV2(metadata.oauth_client_secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue