mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-23 12:45:38 +00:00
fix(bru-1939): fix OAuth2 credentials not persisting across requests in the same collection run. (#5730)
This commit is contained in:
@@ -24,7 +24,7 @@ const { chooseFileToSave, writeBinaryFile, writeFile } = require('../../utils/fi
|
||||
const { addCookieToJar, getDomainsWithCookies, getCookieStringForUrl } = require('../../utils/cookies');
|
||||
const { createFormData } = require('../../utils/form-data');
|
||||
const { findItemInCollectionByPathname, sortFolder, getAllRequestsInFolderRecursively, getEnvVars, getTreePathFromCollectionToItem, mergeVars, sortByNameThenSequence } = require('../../utils/collection');
|
||||
const { getOAuth2TokenUsingAuthorizationCode, getOAuth2TokenUsingClientCredentials, getOAuth2TokenUsingPasswordCredentials, getOAuth2TokenUsingImplicitGrant } = require('../../utils/oauth2');
|
||||
const { getOAuth2TokenUsingAuthorizationCode, getOAuth2TokenUsingClientCredentials, getOAuth2TokenUsingPasswordCredentials, getOAuth2TokenUsingImplicitGrant, updateCollectionOauth2Credentials } = require('../../utils/oauth2');
|
||||
const { preferencesUtil } = require('../../store/preferences');
|
||||
const { getProcessEnvVars } = require('../../store/process-env');
|
||||
const { getBrunoConfig } = require('../../store/bruno-config');
|
||||
@@ -1126,6 +1126,13 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
...(request?.oauth2Credentials?.folderUid ? { folderUid: request.oauth2Credentials.folderUid } : { itemUid: item.uid }),
|
||||
debugInfo: request?.oauth2Credentials?.debugInfo,
|
||||
});
|
||||
|
||||
collection.oauth2Credentials = updateCollectionOauth2Credentials({
|
||||
itemUid: item.uid,
|
||||
collectionUid,
|
||||
collectionOauth2Credentials: collection.oauth2Credentials,
|
||||
requestOauth2Credentials: request.oauth2Credentials
|
||||
});
|
||||
}
|
||||
|
||||
timeStart = Date.now();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { get, cloneDeep } = require('lodash');
|
||||
const { get, cloneDeep, filter } = require('lodash');
|
||||
const crypto = require('crypto');
|
||||
const { authorizeUserInWindow } = require('../ipc/network/authorize-user-in-window');
|
||||
const Oauth2Store = require('../store/oauth2');
|
||||
@@ -894,6 +894,30 @@ const getOAuth2TokenUsingImplicitGrant = async ({ request, collectionUid, forceF
|
||||
}
|
||||
};
|
||||
|
||||
const updateCollectionOauth2Credentials = ({ collectionUid, itemUid, collectionOauth2Credentials = [], requestOauth2Credentials = {} }) => {
|
||||
const { url, credentialsId, folderUid, credentials, debugInfo } = requestOauth2Credentials;
|
||||
|
||||
// Remove existing credentials for the same combination
|
||||
const filteredOauth2Credentials = filter(cloneDeep(collectionOauth2Credentials),
|
||||
(creds) =>
|
||||
!(creds.url === url
|
||||
&& creds.collectionUid === collectionUid
|
||||
&& creds.credentialsId === credentialsId));
|
||||
|
||||
// Add the new credential with folderUid and itemUid
|
||||
filteredOauth2Credentials.push({
|
||||
collectionUid,
|
||||
folderUid: folderUid,
|
||||
itemUid: folderUid ? null : itemUid,
|
||||
url,
|
||||
credentials,
|
||||
credentialsId,
|
||||
debugInfo
|
||||
});
|
||||
|
||||
return filteredOauth2Credentials;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
persistOauth2Credentials,
|
||||
clearOauth2Credentials,
|
||||
@@ -904,5 +928,6 @@ module.exports = {
|
||||
getOAuth2TokenUsingImplicitGrant,
|
||||
refreshOauth2Token,
|
||||
generateCodeVerifier,
|
||||
generateCodeChallenge
|
||||
};
|
||||
generateCodeChallenge,
|
||||
updateCollectionOauth2Credentials
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user