Merge pull request #1667 from lohxt1/feature/BRU-18--inherit-auth-mode

feat(#BRU-18) : "inherit" auth mode for inheriting auth to requests from collection
This commit is contained in:
Anoop M D
2024-02-27 01:12:15 +05:30
committed by GitHub
9 changed files with 63 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('awsv4');
}}
>
@@ -47,7 +47,7 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('basic');
}}
>
@@ -56,7 +56,7 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('bearer');
}}
>
@@ -65,7 +65,7 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('digest');
}}
>
@@ -74,7 +74,16 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('inherit');
}}
>
Inherit
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('oauth2');
}}
>
@@ -83,7 +92,7 @@ const AuthMode = ({ item, collection }) => {
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
dropdownTippyRef?.current?.hide();
onModeChange('none');
}}
>

View File

@@ -1,5 +1,11 @@
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;

View File

@@ -6,11 +6,15 @@ import BearerAuth from './BearerAuth';
import BasicAuth from './BasicAuth';
import DigestAuth from './DigestAuth';
import StyledWrapper from './StyledWrapper';
import { humanizeRequestAuthMode } from 'utils/collections/index';
import OAuth2 from './OAuth2/index';
const Auth = ({ item, collection }) => {
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 = () => {
switch (authMode) {
case 'awsv4': {
@@ -28,7 +32,14 @@ const Auth = ({ item, collection }) => {
case 'oauth2': {
return <OAuth2 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>
);
}
};
return (

View File

@@ -489,6 +489,10 @@ export const humanizeRequestBodyMode = (mode) => {
export const humanizeRequestAuthMode = (mode) => {
let label = 'No Auth';
switch (mode) {
case 'inherit': {
label = 'Inherit';
break;
}
case 'awsv4': {
label = 'AWS Sig V4';
break;

View File

@@ -36,7 +36,7 @@ const prepareRequest = (request, collectionRoot) => {
// But it cannot override the collection auth with no auth
// We will provide support for disabling the auth via scripting in the future
const collectionAuth = get(collectionRoot, 'request.auth');
if (collectionAuth) {
if (collectionAuth && request.auth.mode == 'inherit') {
if (collectionAuth.mode === 'basic') {
axiosRequest.auth = {
username: get(collectionAuth, 'basic.username'),

View File

@@ -35,7 +35,7 @@ const parseFormData = (datas, collectionPath) => {
// We will provide support for disabling the auth via scripting in the future
const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
const collectionAuth = get(collectionRoot, 'request.auth');
if (collectionAuth) {
if (collectionAuth && request.auth.mode == 'inherit') {
switch (collectionAuth.mode) {
case 'awsv4':
axiosRequest.awsv4config = {

View File

@@ -168,7 +168,7 @@ const oauth2Schema = Yup.object({
.strict();
const authSchema = Yup.object({
mode: Yup.string().oneOf(['none', 'awsv4', 'basic', 'bearer', 'digest', 'oauth2']).required('mode is required'),
mode: Yup.string().oneOf(['inherit', 'none', 'awsv4', 'basic', 'bearer', 'digest', 'oauth2']).required('mode is required'),
awsv4: authAwsV4Schema.nullable(),
basic: authBasicSchema.nullable(),
bearer: authBearerSchema.nullable(),

View File

@@ -0,0 +1,20 @@
meta {
name: inherit Bearer Auth 200
type: http
seq: 2
}
get {
url: {{host}}/api/auth/bearer/protected
body: none
auth: inherit
}
assert {
res.status: 200
res.body.message: Authentication successful
}
script:post-response {
bru.setEnvVar("foo", "bar");
}

View File

@@ -3,7 +3,7 @@ headers {
}
auth {
mode: none
mode: bearer
}
auth:basic {
@@ -12,7 +12,7 @@ auth:basic {
}
auth:bearer {
token: {{bearerAuthToken}}
token: {{bearer_auth_token}}
}
docs {