Skip to content

Commit 0d8a696

Browse files
authored
Merge pull request #4609 from pooja-bruno/feat/extend-support-for-more-auth-for-folder-level
feat: extend support for more auth in folder level
2 parents bfa2706 + fbd3a38 commit 0d8a696

File tree

14 files changed

+377
-51
lines changed

14 files changed

+377
-51
lines changed

packages/bruno-app/src/components/FolderSettings/Auth/StyledWrapper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ const Wrapper = styled.div`
1111
border: solid 1px ${(props) => props.theme.input.border};
1212
background-color: ${(props) => props.theme.input.bg};
1313
}
14+
.inherit-mode-text {
15+
color: ${(props) => props.theme.colors.text.yellow};
16+
}
17+
.auth-mode-label {
18+
color: ${(props) => props.theme.colors.text.yellow};
19+
}
1420
`;
1521

1622
export default Wrapper;

packages/bruno-app/src/components/FolderSettings/Auth/index.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import OAuth2PasswordCredentials from 'components/RequestPane/Auth/OAuth2/Passwo
99
import OAuth2ClientCredentials from 'components/RequestPane/Auth/OAuth2/ClientCredentials/index';
1010
import GrantTypeSelector from 'components/RequestPane/Auth/OAuth2/GrantTypeSelector/index';
1111
import AuthMode from '../AuthMode';
12+
import BasicAuth from 'components/RequestPane/Auth/BasicAuth';
13+
import BearerAuth from 'components/RequestPane/Auth/BearerAuth';
14+
import DigestAuth from 'components/RequestPane/Auth/DigestAuth';
15+
import NTLMAuth from 'components/RequestPane/Auth/NTLMAuth';
16+
import WsseAuth from 'components/RequestPane/Auth/WsseAuth';
17+
import ApiKeyAuth from 'components/RequestPane/Auth/ApiKeyAuth';
18+
import AwsV4Auth from 'components/RequestPane/Auth/AwsV4Auth';
19+
import { findItemInCollection, findParentItemInCollection, humanizeRequestAuthMode } from 'utils/collections/index';
1220

1321
const GrantTypeComponentMap = ({ collection, folder }) => {
1422
const dispatch = useDispatch();
@@ -37,12 +45,132 @@ const Auth = ({ collection, folder }) => {
3745
let request = get(folder, 'root.request', {});
3846
const authMode = get(folder, 'root.request.auth.mode');
3947

48+
const getTreePathFromCollectionToFolder = (collection, _folder) => {
49+
let path = [];
50+
let item = findItemInCollection(collection, _folder?.uid);
51+
while (item) {
52+
path.unshift(item);
53+
item = findParentItemInCollection(collection, item?.uid);
54+
}
55+
return path;
56+
};
57+
58+
const getEffectiveAuthSource = () => {
59+
if (authMode !== 'inherit') return null;
60+
61+
const collectionAuth = get(collection, 'root.request.auth');
62+
let effectiveSource = {
63+
type: 'collection',
64+
name: 'Collection',
65+
auth: collectionAuth
66+
};
67+
68+
// Get path from collection to current folder
69+
const folderTreePath = getTreePathFromCollectionToFolder(collection, folder);
70+
71+
// Check parent folders to find closest auth configuration
72+
// Skip the last item which is the current folder
73+
for (let i = 0; i < folderTreePath.length - 1; i++) {
74+
const parentFolder = folderTreePath[i];
75+
if (parentFolder.type === 'folder') {
76+
const folderAuth = get(parentFolder, 'root.request.auth');
77+
if (folderAuth && folderAuth.mode && folderAuth.mode !== 'none' && folderAuth.mode !== 'inherit') {
78+
effectiveSource = {
79+
type: 'folder',
80+
name: parentFolder.name,
81+
auth: folderAuth
82+
};
83+
break;
84+
}
85+
}
86+
}
87+
88+
return effectiveSource;
89+
};
90+
4091
const handleSave = () => {
4192
dispatch(saveFolderRoot(collection.uid, folder.uid));
4293
};
4394

4495
const getAuthView = () => {
4596
switch (authMode) {
97+
case 'basic': {
98+
return (
99+
<BasicAuth
100+
collection={collection}
101+
item={folder}
102+
updateAuth={updateFolderAuth}
103+
request={request}
104+
save={() => handleSave()}
105+
/>
106+
);
107+
}
108+
case 'bearer': {
109+
return (
110+
<BearerAuth
111+
collection={collection}
112+
item={folder}
113+
updateAuth={updateFolderAuth}
114+
request={request}
115+
save={() => handleSave()}
116+
/>
117+
);
118+
}
119+
case 'digest': {
120+
return (
121+
<DigestAuth
122+
collection={collection}
123+
item={folder}
124+
updateAuth={updateFolderAuth}
125+
request={request}
126+
save={() => handleSave()}
127+
/>
128+
);
129+
}
130+
case 'ntlm': {
131+
return (
132+
<NTLMAuth
133+
collection={collection}
134+
item={folder}
135+
updateAuth={updateFolderAuth}
136+
request={request}
137+
save={() => handleSave()}
138+
/>
139+
);
140+
}
141+
case 'wsse': {
142+
return (
143+
<WsseAuth
144+
collection={collection}
145+
item={folder}
146+
updateAuth={updateFolderAuth}
147+
request={request}
148+
save={() => handleSave()}
149+
/>
150+
);
151+
}
152+
case 'apikey': {
153+
return (
154+
<ApiKeyAuth
155+
collection={collection}
156+
item={folder}
157+
updateAuth={updateFolderAuth}
158+
request={request}
159+
save={() => handleSave()}
160+
/>
161+
);
162+
}
163+
case 'awsv4': {
164+
return (
165+
<AwsV4Auth
166+
collection={collection}
167+
item={folder}
168+
updateAuth={updateFolderAuth}
169+
request={request}
170+
save={() => handleSave()}
171+
/>
172+
);
173+
}
46174
case 'oauth2': {
47175
return (
48176
<>
@@ -56,6 +184,17 @@ const Auth = ({ collection, folder }) => {
56184
</>
57185
);
58186
}
187+
case 'inherit': {
188+
const source = getEffectiveAuthSource();
189+
return (
190+
<>
191+
<div className="flex flex-row w-full mt-2 gap-2">
192+
<div>Auth inherited from {source.name}: </div>
193+
<div className="inherit-mode-text">{humanizeRequestAuthMode(source.auth?.mode)}</div>
194+
</div>
195+
</>
196+
);
197+
}
59198
case 'none': {
60199
return null;
61200
}
@@ -64,6 +203,7 @@ const Auth = ({ collection, folder }) => {
64203
}
65204
};
66205

206+
67207
return (
68208
<StyledWrapper className="w-full">
69209
<div className="text-xs mb-4 text-muted">

packages/bruno-app/src/components/FolderSettings/AuthMode/index.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,51 @@ const AuthMode = ({ collection, folder }) => {
3535
<StyledWrapper>
3636
<div className="inline-flex items-center cursor-pointer">
3737
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
38+
<div
39+
className="dropdown-item"
40+
onClick={() => {
41+
dropdownTippyRef.current.hide();
42+
onModeChange('awsv4');
43+
}}
44+
>
45+
AWS Sig v4
46+
</div>
47+
<div
48+
className="dropdown-item"
49+
onClick={() => {
50+
dropdownTippyRef.current.hide();
51+
onModeChange('basic');
52+
}}
53+
>
54+
Basic Auth
55+
</div>
56+
<div
57+
className="dropdown-item"
58+
onClick={() => {
59+
dropdownTippyRef.current.hide();
60+
onModeChange('bearer');
61+
}}
62+
>
63+
Bearer Token
64+
</div>
65+
<div
66+
className="dropdown-item"
67+
onClick={() => {
68+
dropdownTippyRef.current.hide();
69+
onModeChange('digest');
70+
}}
71+
>
72+
Digest Auth
73+
</div>
74+
<div
75+
className="dropdown-item"
76+
onClick={() => {
77+
dropdownTippyRef.current.hide();
78+
onModeChange('ntlm');
79+
}}
80+
>
81+
NTLM Auth
82+
</div>
3883
<div
3984
className="dropdown-item"
4085
onClick={() => {
@@ -44,6 +89,33 @@ const AuthMode = ({ collection, folder }) => {
4489
>
4590
OAuth 2.0
4691
</div>
92+
<div
93+
className="dropdown-item"
94+
onClick={() => {
95+
dropdownTippyRef.current.hide();
96+
onModeChange('wsse');
97+
}}
98+
>
99+
WSSE Auth
100+
</div>
101+
<div
102+
className="dropdown-item"
103+
onClick={() => {
104+
dropdownTippyRef.current.hide();
105+
onModeChange('apikey');
106+
}}
107+
>
108+
API Key
109+
</div>
110+
<div
111+
className="dropdown-item"
112+
onClick={() => {
113+
dropdownTippyRef.current.hide();
114+
onModeChange('inherit');
115+
}}
116+
>
117+
Inherit
118+
</div>
47119
<div
48120
className="dropdown-item"
49121
onClick={() => {

packages/bruno-app/src/components/RequestPane/Auth/ApiKeyAuth/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ import { IconCaretDown } from '@tabler/icons';
55
import Dropdown from 'components/Dropdown';
66
import { useTheme } from 'providers/Theme';
77
import SingleLineEditor from 'components/SingleLineEditor';
8-
import { updateAuth } from 'providers/ReduxStore/slices/collections';
9-
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
8+
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
109
import StyledWrapper from './StyledWrapper';
1110
import { humanizeRequestAPIKeyPlacement } from 'utils/collections';
1211

13-
const ApiKeyAuth = ({ item, collection }) => {
12+
const ApiKeyAuth = ({ item, collection, updateAuth, request, save }) => {
1413
const dispatch = useDispatch();
1514
const { storedTheme } = useTheme();
1615
const dropdownTippyRef = useRef();
1716
const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref);
1817

19-
const apikeyAuth = item.draft ? get(item, 'draft.request.auth.apikey', {}) : get(item, 'request.auth.apikey', {});
18+
const apikeyAuth = get(request, 'auth.apikey', {});
2019

2120
const handleRun = () => dispatch(sendRequest(item, collection.uid));
22-
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid));
21+
22+
const handleSave = () => {
23+
save();
24+
};
2325

2426
const Icon = forwardRef((props, ref) => {
2527
return (
@@ -90,7 +92,7 @@ const ApiKeyAuth = ({ item, collection }) => {
9092
<div
9193
className="dropdown-item"
9294
onClick={() => {
93-
dropdownTippyRef.current.hide();
95+
dropdownTippyRef?.current?.hide();
9496
handleAuthChange('placement', 'header');
9597
}}
9698
>
@@ -99,11 +101,11 @@ const ApiKeyAuth = ({ item, collection }) => {
99101
<div
100102
className="dropdown-item"
101103
onClick={() => {
102-
dropdownTippyRef.current.hide();
104+
dropdownTippyRef?.current?.hide();
103105
handleAuthChange('placement', 'queryparams');
104106
}}
105107
>
106-
Query Params
108+
Query Param
107109
</div>
108110
</Dropdown>
109111
</div>

packages/bruno-app/src/components/RequestPane/Auth/AwsV4Auth/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collection
88
import StyledWrapper from './StyledWrapper';
99
import { update } from 'lodash';
1010

11-
const AwsV4Auth = ({ onTokenChange, item, collection }) => {
11+
const AwsV4Auth = ({ item, collection, updateAuth, request, save }) => {
1212
const dispatch = useDispatch();
1313
const { storedTheme } = useTheme();
1414

15-
const awsv4Auth = item.draft ? get(item, 'draft.request.auth.awsv4', {}) : get(item, 'request.auth.awsv4', {});
15+
const awsv4Auth = get(request, 'auth.awsv4', {});
1616

1717
const handleRun = () => dispatch(sendRequest(item, collection.uid));
18-
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid));
18+
19+
const handleSave = () => {
20+
save();
21+
};
1922

2023
const handleAccessKeyIdChange = (accessKeyId) => {
2124
dispatch(

packages/bruno-app/src/components/RequestPane/Auth/BasicAuth/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import { updateAuth } from 'providers/ReduxStore/slices/collections';
77
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
88
import StyledWrapper from './StyledWrapper';
99

10-
const BasicAuth = ({ item, collection }) => {
10+
const BasicAuth = ({ item, collection, updateAuth, request, save }) => {
1111
const dispatch = useDispatch();
1212
const { storedTheme } = useTheme();
1313

14-
const basicAuth = item.draft ? get(item, 'draft.request.auth.basic', {}) : get(item, 'request.auth.basic', {});
14+
const basicAuth = get(request, 'auth.basic', {});
1515

1616
const handleRun = () => dispatch(sendRequest(item, collection.uid));
17-
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid));
17+
18+
const handleSave = () => {
19+
save();
20+
};
1821

1922
const handleUsernameChange = (username) => {
2023
dispatch(

packages/bruno-app/src/components/RequestPane/Auth/BearerAuth/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import { updateAuth } from 'providers/ReduxStore/slices/collections';
77
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
88
import StyledWrapper from './StyledWrapper';
99

10-
const BearerAuth = ({ item, collection }) => {
10+
const BearerAuth = ({ item, collection, updateAuth, request, save }) => {
1111
const dispatch = useDispatch();
1212
const { storedTheme } = useTheme();
1313

14-
const bearerToken = item.draft
15-
? get(item, 'draft.request.auth.bearer.token', '')
16-
: get(item, 'request.auth.bearer.token', '');
14+
// Use the request prop directly like OAuth2ClientCredentials does
15+
const bearerToken = get(request, 'auth.bearer.token', '');
1716

1817
const handleRun = () => dispatch(sendRequest(item, collection.uid));
19-
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid));
18+
19+
const handleSave = () => {
20+
save();
21+
};
2022

2123
const handleTokenChange = (token) => {
2224
dispatch(

0 commit comments

Comments
 (0)