fix(bru-1928): bruno-cli oauth2 updates (#5729)

This commit is contained in:
lohit
2025-10-07 22:38:52 +05:30
committed by GitHub
parent c1853e613b
commit 10739c32c4
11 changed files with 469 additions and 134 deletions

View File

@@ -0,0 +1,50 @@
// 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;
},
// 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;