mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 21:25:45 +00:00
* fix: oauth2 credential management improvements Add bru.resetOauth2Credential() API for programmatic credential invalidation from scripts, fix credential clearing to match on credentialsId, expose oauth2 credential variables in test runtime, and add input validation with deduplication to prevent redundant IPC messages. Remove unused collectionGetOauth2CredentialsByUrlAndCredentialsId reducer. * fix: handle invalid URLs in oauth2 callback redirect handler Wrap new URL() calls in try-catch within onWindowRedirect to prevent uncaught TypeError when redirect or callback URLs are invalid. * Update packages/bruno-app/src/utils/codemirror/autocomplete.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
// In-memory credential store implementation for OAuth2 credentials
|
|
const tokenStore = {
|
|
credentials: {},
|
|
|
|
// Save credentials
|
|
async saveCredential({ url, credentialsId, credentials }) {
|
|
if (!this.credentials[credentialsId]) {
|
|
this.credentials[credentialsId] = {};
|
|
}
|
|
this.credentials[credentialsId][url] = credentials;
|
|
return true;
|
|
},
|
|
|
|
// Get credentials
|
|
async getCredential({ url, credentialsId }) {
|
|
return this.credentials[credentialsId]?.[url];
|
|
},
|
|
|
|
// Delete credentials
|
|
async deleteCredential({ url, credentialsId }) {
|
|
if (this.credentials[credentialsId]?.[url]) {
|
|
delete this.credentials[credentialsId][url];
|
|
// Clean up empty credentialsId objects
|
|
if (Object.keys(this.credentials[credentialsId]).length === 0) {
|
|
delete this.credentials[credentialsId];
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
// Delete all credentials for a given credentialsId (all URLs)
|
|
deleteCredentialById(credentialsId) {
|
|
if (this.credentials[credentialsId]) {
|
|
delete this.credentials[credentialsId];
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
// Get all stored OAuth2 credentials
|
|
getAllCredentials() {
|
|
const result = [];
|
|
for (const [credentialsId, urlMap] of Object.entries(this.credentials)) {
|
|
for (const [url, credentials] of Object.entries(urlMap)) {
|
|
if (credentials) {
|
|
result.push({
|
|
url,
|
|
credentialsId,
|
|
credentials
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
|
|
module.exports = tokenStore;
|