mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
feat(#1655): inherit auth mode for requests
This commit is contained in:
parent
117726a01f
commit
3c2cbe63c4
@ -35,6 +35,15 @@ const AuthMode = ({ item, collection }) => {
|
|||||||
<StyledWrapper>
|
<StyledWrapper>
|
||||||
<div className="inline-flex items-center cursor-pointer auth-mode-selector">
|
<div className="inline-flex items-center cursor-pointer auth-mode-selector">
|
||||||
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
|
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
|
||||||
|
<div
|
||||||
|
className="dropdown-item"
|
||||||
|
onClick={() => {
|
||||||
|
dropdownTippyRef.current.hide();
|
||||||
|
onModeChange('inherit');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Inherit
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
const Wrapper = styled.div``;
|
const Wrapper = styled.div`
|
||||||
|
.inherit-mode-text {
|
||||||
|
color: ${(props) => props.theme.colors.text.yellow};
|
||||||
|
}
|
||||||
|
.inherit-mode-label {
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export default Wrapper;
|
export default Wrapper;
|
||||||
|
@ -6,10 +6,14 @@ import BearerAuth from './BearerAuth';
|
|||||||
import BasicAuth from './BasicAuth';
|
import BasicAuth from './BasicAuth';
|
||||||
import DigestAuth from './DigestAuth';
|
import DigestAuth from './DigestAuth';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
import { humanizeRequestAuthMode } from 'utils/collections/index';
|
||||||
|
|
||||||
const Auth = ({ item, collection }) => {
|
const Auth = ({ item, collection }) => {
|
||||||
const authMode = item.draft ? get(item, 'draft.request.auth.mode') : get(item, 'request.auth.mode');
|
const authMode = item.draft ? get(item, 'draft.request.auth.mode') : get(item, 'request.auth.mode');
|
||||||
|
|
||||||
|
const collectionRoot = get(collection, 'root', {});
|
||||||
|
const collectionAuth = get(collectionRoot, 'request.auth');
|
||||||
|
|
||||||
const getAuthView = () => {
|
const getAuthView = () => {
|
||||||
switch (authMode) {
|
switch (authMode) {
|
||||||
case 'awsv4': {
|
case 'awsv4': {
|
||||||
@ -24,6 +28,14 @@ const Auth = ({ item, collection }) => {
|
|||||||
case 'digest': {
|
case 'digest': {
|
||||||
return <DigestAuth collection={collection} item={item} />;
|
return <DigestAuth collection={collection} item={item} />;
|
||||||
}
|
}
|
||||||
|
case 'inherit': {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-row w-full mt-2 gap-4">
|
||||||
|
<div>Auth inherited from the Collection: </div>
|
||||||
|
<div className="inherit-mode-text">{humanizeRequestAuthMode(collectionAuth?.mode)}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -489,6 +489,10 @@ export const humanizeRequestBodyMode = (mode) => {
|
|||||||
export const humanizeRequestAuthMode = (mode) => {
|
export const humanizeRequestAuthMode = (mode) => {
|
||||||
let label = 'No Auth';
|
let label = 'No Auth';
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
case 'inherit': {
|
||||||
|
label = 'Inherit';
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'awsv4': {
|
case 'awsv4': {
|
||||||
label = 'AWS Sig V4';
|
label = 'AWS Sig V4';
|
||||||
break;
|
break;
|
||||||
|
@ -36,7 +36,7 @@ const prepareRequest = (request, collectionRoot) => {
|
|||||||
// But it cannot override the collection auth with no auth
|
// But it cannot override the collection auth with no auth
|
||||||
// We will provide support for disabling the auth via scripting in the future
|
// We will provide support for disabling the auth via scripting in the future
|
||||||
const collectionAuth = get(collectionRoot, 'request.auth');
|
const collectionAuth = get(collectionRoot, 'request.auth');
|
||||||
if (collectionAuth) {
|
if (collectionAuth && request.auth.mode == 'inherit') {
|
||||||
if (collectionAuth.mode === 'basic') {
|
if (collectionAuth.mode === 'basic') {
|
||||||
axiosRequest.auth = {
|
axiosRequest.auth = {
|
||||||
username: get(collectionAuth, 'basic.username'),
|
username: get(collectionAuth, 'basic.username'),
|
||||||
|
@ -35,7 +35,7 @@ const parseFormData = (datas, collectionPath) => {
|
|||||||
// We will provide support for disabling the auth via scripting in the future
|
// We will provide support for disabling the auth via scripting in the future
|
||||||
const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
|
const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
|
||||||
const collectionAuth = get(collectionRoot, 'request.auth');
|
const collectionAuth = get(collectionRoot, 'request.auth');
|
||||||
if (collectionAuth) {
|
if (collectionAuth && request.auth.mode == 'inherit') {
|
||||||
switch (collectionAuth.mode) {
|
switch (collectionAuth.mode) {
|
||||||
case 'awsv4':
|
case 'awsv4':
|
||||||
axiosRequest.awsv4config = {
|
axiosRequest.awsv4config = {
|
||||||
|
@ -120,7 +120,7 @@ const authDigestSchema = Yup.object({
|
|||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
const authSchema = Yup.object({
|
const authSchema = Yup.object({
|
||||||
mode: Yup.string().oneOf(['none', 'awsv4', 'basic', 'bearer', 'digest']).required('mode is required'),
|
mode: Yup.string().oneOf(['inherit', 'none', 'awsv4', 'basic', 'bearer', 'digest']).required('mode is required'),
|
||||||
awsv4: authAwsV4Schema.nullable(),
|
awsv4: authAwsV4Schema.nullable(),
|
||||||
basic: authBasicSchema.nullable(),
|
basic: authBasicSchema.nullable(),
|
||||||
bearer: authBearerSchema.nullable(),
|
bearer: authBearerSchema.nullable(),
|
||||||
|
Loading…
Reference in New Issue
Block a user