mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import React from 'react';
|
|
import SensitiveFieldWarning from 'components/SensitiveFieldWarning';
|
|
import { useDetectSensitiveField } from 'hooks/useDetectSensitiveField';
|
|
import get from 'lodash/get';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { useDispatch } from 'react-redux';
|
|
import SingleLineEditor from 'components/SingleLineEditor';
|
|
import { updateAuth } from 'providers/ReduxStore/slices/collections';
|
|
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const BearerAuth = ({ item, collection, updateAuth, request, save }) => {
|
|
const dispatch = useDispatch();
|
|
const { storedTheme } = useTheme();
|
|
|
|
// Use the request prop directly like OAuth2ClientCredentials does
|
|
const bearerToken = get(request, 'auth.bearer.token', '');
|
|
const { isSensitive } = useDetectSensitiveField(collection);
|
|
const { showWarning, warningMessage } = isSensitive(bearerToken);
|
|
|
|
const handleRun = () => dispatch(sendRequest(item, collection.uid));
|
|
|
|
const handleSave = () => {
|
|
save();
|
|
};
|
|
|
|
const handleTokenChange = (token) => {
|
|
dispatch(
|
|
updateAuth({
|
|
mode: 'bearer',
|
|
collectionUid: collection.uid,
|
|
itemUid: item.uid,
|
|
content: {
|
|
token: token
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
return (
|
|
<StyledWrapper className="mt-2 w-full">
|
|
<label className="block font-medium mb-2">Token</label>
|
|
<div className="single-line-editor-wrapper flex items-center">
|
|
<SingleLineEditor
|
|
value={bearerToken}
|
|
theme={storedTheme}
|
|
onSave={handleSave}
|
|
onChange={(val) => handleTokenChange(val)}
|
|
onRun={handleRun}
|
|
collection={collection}
|
|
item={item}
|
|
isSecret={true}
|
|
/>
|
|
{showWarning && <SensitiveFieldWarning fieldName="bearer-token" warningMessage={warningMessage} />}
|
|
</div>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default BearerAuth;
|