mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 14:08:38 +00:00
105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
import React, { useMemo, useCallback } from 'react';
|
|
import get from 'lodash/get';
|
|
import { IconCaretDown } from '@tabler/icons';
|
|
import MenuDropdown from 'ui/MenuDropdown';
|
|
import StatusBadge from 'ui/StatusBadge/index';
|
|
import { useDispatch } from 'react-redux';
|
|
import { updateCollectionAuthMode } from 'providers/ReduxStore/slices/collections';
|
|
import { humanizeRequestAuthMode } from 'utils/collections';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const AuthMode = ({ collection }) => {
|
|
const dispatch = useDispatch();
|
|
const authMode = collection.draft?.root ? get(collection, 'draft.root.request.auth.mode') : get(collection, 'root.request.auth.mode');
|
|
|
|
const onModeChange = useCallback((value) => {
|
|
dispatch(
|
|
updateCollectionAuthMode({
|
|
collectionUid: collection.uid,
|
|
mode: value
|
|
})
|
|
);
|
|
}, [dispatch, collection.uid]);
|
|
|
|
const menuItems = useMemo(() => [
|
|
{
|
|
id: 'awsv4',
|
|
label: 'AWS Sig v4',
|
|
onClick: () => onModeChange('awsv4')
|
|
},
|
|
{
|
|
id: 'basic',
|
|
label: 'Basic Auth',
|
|
onClick: () => onModeChange('basic')
|
|
},
|
|
{
|
|
id: 'wsse',
|
|
label: 'WSSE Auth',
|
|
onClick: () => onModeChange('wsse')
|
|
},
|
|
{
|
|
id: 'bearer',
|
|
label: 'Bearer Token',
|
|
onClick: () => onModeChange('bearer')
|
|
},
|
|
{
|
|
id: 'digest',
|
|
label: 'Digest Auth',
|
|
onClick: () => onModeChange('digest')
|
|
},
|
|
{
|
|
id: 'ntlm',
|
|
label: 'NTLM Auth',
|
|
onClick: () => onModeChange('ntlm')
|
|
},
|
|
{
|
|
id: 'oauth1',
|
|
label: 'OAuth 1.0',
|
|
onClick: () => onModeChange('oauth1')
|
|
},
|
|
{
|
|
id: 'oauth2',
|
|
label: 'OAuth 2.0',
|
|
onClick: () => onModeChange('oauth2')
|
|
},
|
|
{
|
|
id: 'apikey',
|
|
label: 'API Key',
|
|
onClick: () => onModeChange('apikey')
|
|
},
|
|
{
|
|
id: 'akamai-edgegrid',
|
|
label: (
|
|
<span className="flex items-center gap-2">
|
|
Akamai EdgeGrid
|
|
<StatusBadge status="info" size="xs">Beta</StatusBadge>
|
|
</span>
|
|
),
|
|
ariaLabel: 'Akamai EdgeGrid (Beta)',
|
|
onClick: () => onModeChange('akamai-edgegrid')
|
|
},
|
|
{
|
|
id: 'none',
|
|
label: 'No Auth',
|
|
onClick: () => onModeChange('none')
|
|
}
|
|
], [onModeChange]);
|
|
|
|
return (
|
|
<StyledWrapper>
|
|
<div className="inline-flex items-center cursor-pointer auth-mode-selector" data-testid="auth-mode-selector">
|
|
<MenuDropdown
|
|
items={menuItems}
|
|
placement="bottom-end"
|
|
selectedItemId={authMode}
|
|
>
|
|
<div className="flex items-center justify-center auth-mode-label select-none" data-testid="auth-mode-label">
|
|
{humanizeRequestAuthMode(authMode)} <IconCaretDown className="caret ml-1" size={14} strokeWidth={2} />
|
|
</div>
|
|
</MenuDropdown>
|
|
</div>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
export default AuthMode;
|