mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 14:08:38 +00:00
fix: Inherited apikey auth mapping for bruno-cli (#3512)
* Added bruno-cli support for mapping inherited apikey auth from collection Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
@@ -36,7 +36,7 @@ const prepareRequest = (item = {}, collection = {}) => {
|
||||
};
|
||||
|
||||
const collectionAuth = get(collection, 'root.request.auth');
|
||||
if (collectionAuth && request.auth.mode === 'inherit') {
|
||||
if (collectionAuth && request.auth?.mode === 'inherit') {
|
||||
if (collectionAuth.mode === 'basic') {
|
||||
axiosRequest.auth = {
|
||||
username: get(collectionAuth, 'basic.username'),
|
||||
@@ -47,9 +47,27 @@ const prepareRequest = (item = {}, collection = {}) => {
|
||||
if (collectionAuth.mode === 'bearer') {
|
||||
axiosRequest.headers['Authorization'] = `Bearer ${get(collectionAuth, 'bearer.token')}`;
|
||||
}
|
||||
|
||||
if (collectionAuth.mode === 'apikey') {
|
||||
if (collectionAuth.apikey?.placement === 'header') {
|
||||
axiosRequest.headers[collectionAuth.apikey?.key] = collectionAuth.apikey?.value;
|
||||
}
|
||||
|
||||
if (collectionAuth.apikey?.placement === 'queryparams') {
|
||||
if (axiosRequest.url && collectionAuth.apikey?.key) {
|
||||
try {
|
||||
const urlObj = new URL(request.url);
|
||||
urlObj.searchParams.set(collectionAuth.apikey?.key, collectionAuth.apikey?.value);
|
||||
axiosRequest.url = urlObj.toString();
|
||||
} catch (error) {
|
||||
console.error('Invalid URL:', request.url, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
if (request.auth && request.auth.mode !== 'inherit') {
|
||||
if (request.auth.mode === 'basic') {
|
||||
axiosRequest.auth = {
|
||||
username: get(request, 'auth.basic.username'),
|
||||
|
||||
Reference in New Issue
Block a user