mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-30 16:14:06 +00:00
committed by
GitHub
parent
b432e94a4e
commit
a0df5138b3
30
packages/bruno-app/src/utils/codegenerator/auth.js
Normal file
30
packages/bruno-app/src/utils/codegenerator/auth.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import get from 'lodash/get';
|
||||
|
||||
export const getAuthHeaders = (collectionRootAuth, requestAuth) => {
|
||||
const auth = collectionRootAuth && ['inherit', 'none'].includes(requestAuth.mode) ? collectionRootAuth : requestAuth;
|
||||
|
||||
switch (auth.mode) {
|
||||
case 'basic':
|
||||
const username = get(auth, 'basic.username');
|
||||
const password = get(auth, 'basic.password');
|
||||
const basicToken = Buffer.from(`${username}:${password}`).toString('base64');
|
||||
|
||||
return [
|
||||
{
|
||||
enabled: true,
|
||||
name: 'Authorization',
|
||||
value: `Basic ${basicToken}`
|
||||
}
|
||||
];
|
||||
case 'bearer':
|
||||
return [
|
||||
{
|
||||
enabled: true,
|
||||
name: 'Authorization',
|
||||
value: `Bearer ${get(auth, 'bearer.token')}`
|
||||
}
|
||||
];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user