diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/StyledWrapper.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/StyledWrapper.js
new file mode 100644
index 000000000..ebb8ee46a
--- /dev/null
+++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/StyledWrapper.js
@@ -0,0 +1,16 @@
+import styled from 'styled-components';
+
+const StyledWrapper = styled.div`
+ .tabs {
+ .active {
+ border-bottom: solid 1px ${(props) => props.theme.input.border};
+ }
+ }
+ .additional-parameter-sends-in-selector {
+ select {
+ height: 32px;
+ }
+ }
+`
+
+export default StyledWrapper;
\ No newline at end of file
diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/index.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/index.js
index cdee10a49..1e13b676e 100644
--- a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/index.js
+++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AdditionalParams/index.js
@@ -1,77 +1,53 @@
import { useDispatch } from "react-redux";
-import React, { useRef, forwardRef, useState } from 'react';
+import React, { forwardRef, useState } from 'react';
import get from 'lodash/get';
import { useTheme } from 'providers/Theme';
-import { IconPlus } from '@tabler/icons';
-import Dropdown from 'components/Dropdown';
+import { IconPlus, IconCaretDown, IconTrash } from '@tabler/icons';
import { cloneDeep } from "lodash";
+import SingleLineEditor from "components/SingleLineEditor/index";
+import StyledWrapper from "./StyledWrapper";
+import Table from "components/Table/index";
const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();
- const dropdownTippyRef = useRef();
- const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref);
const [activeTab, setActiveTab] = useState('authorization');
const oAuth = get(request, 'auth.oauth2', {});
const {
grantType,
- callbackUrl,
- authorizationUrl,
- accessTokenUrl,
- clientId,
- clientSecret,
- scope,
- credentialsPlacement,
- state,
- pkce,
- credentialsId,
- tokenPlacement,
- tokenHeaderPrefix,
- tokenQueryKey,
- refreshTokenUrl,
- autoRefreshToken,
- autoFetchToken,
- additionalParams = {}
+ additionalParameters = {}
} = oAuth;
- const handleUpdateAdditionalParam = ({ paramType, key, paramIndex, value }) => {
- const updatedAdditionalParams = cloneDeep(additionalParams);
-
- updatedAdditionalParams[paramType][paramIndex][key] = value;
-
+ const updateAdditionalParams = ({ updatedAdditionalParams }) => {
dispatch(
updateAuth({
mode: 'oauth2',
collectionUid: collection.uid,
itemUid: item.uid,
content: {
- grantType,
- callbackUrl,
- authorizationUrl,
- accessTokenUrl,
- clientId,
- clientSecret,
- state,
- scope,
- pkce,
- credentialsPlacement,
- credentialsId,
- tokenPlacement,
- tokenHeaderPrefix,
- tokenQueryKey,
- refreshTokenUrl,
- autoRefreshToken,
- autoFetchToken,
- additionalParams: updatedAdditionalParams,
+ ...oAuth,
+ additionalParameters: updatedAdditionalParams,
}
})
);
}
+ const handleUpdateAdditionalParam = ({ paramType, key, paramIndex, value }) => {
+ const updatedAdditionalParams = cloneDeep(additionalParameters);
+ updatedAdditionalParams[paramType][paramIndex][key] = value;
+ updateAdditionalParams({ updatedAdditionalParams });
+ }
+
+ const handleDeleteAdditionalParam = ({ paramType, paramIndex }) => {
+ const updatedAdditionalParams = cloneDeep(additionalParameters);
+ updatedAdditionalParams[paramType] = updatedAdditionalParams[paramType]?.filter((_, index) => index !== paramIndex);
+ updateAdditionalParams({ updatedAdditionalParams });
+ }
+
const handleAddNewAdditionalParam = () => {
const paramType = activeTab;
- const updatedAdditionalParams = cloneDeep(additionalParams);
+ const updatedAdditionalParams = cloneDeep(additionalParameters);
if (!updatedAdditionalParams?.[paramType]) {
updatedAdditionalParams[paramType] = [];
}
@@ -80,61 +56,35 @@ const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
{
name: '',
value: '',
- sendIn: 'header'
+ sendIn: 'headers',
+ enabled: true
}
];
-
- dispatch(
- updateAuth({
- mode: 'oauth2',
- collectionUid: collection.uid,
- itemUid: item.uid,
- content: {
- grantType,
- callbackUrl,
- authorizationUrl,
- accessTokenUrl,
- clientId,
- clientSecret,
- state,
- scope,
- pkce,
- credentialsPlacement,
- credentialsId,
- tokenPlacement,
- tokenHeaderPrefix,
- tokenQueryKey,
- refreshTokenUrl,
- autoRefreshToken,
- autoFetchToken,
- additionalParams: updatedAdditionalParams,
- }
- })
- );
+ updateAdditionalParams({ updatedAdditionalParams });
}
return (
-
-
-
Authorization
-
Token
-
Refresh
+
+
+
setActiveTab('authorization')}>Authorization
+
setActiveTab('token')}>Token
+
setActiveTab('refresh')}>Refresh
-
-
-
- | Key |
- Value |
- Send In |
-
-
+
- {additionalParams?.[activeTab]?.map((param, index) =>
+ {additionalParameters?.[activeTab]?.map((param, index) =>
- |
+ |
handleUpdateAdditionalParam({
paramType: activeTab,
key: 'name',
@@ -148,7 +98,7 @@ const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
handleUpdateAdditionalParam({
paramType: activeTab,
key: 'value',
@@ -158,59 +108,86 @@ const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
collection={collection}
/>
|
- } placement="bottom-end">
- {
- dropdownTippyRef.current.hide();
- handleUpdateAdditionalParam({
- paramType: activeTab,
- key: 'sendIn',
- paramIndex: index,
- value: 'header'
- })
- }}
- >
- Header
+
+
+
- {
- dropdownTippyRef.current.hide();
- handleUpdateAdditionalParam({
- paramType: activeTab,
- key: 'sendIn',
- paramIndex: index,
- value: 'queryparams'
- })
- }}
- >
- Query Params
+ |
+
+
+ {
+ handleUpdateAdditionalParam({
+ paramType: activeTab,
+ key: 'enabled',
+ paramIndex: index,
+ value: e.target.checked
+ })
+ }}
+ />
+
- {
- dropdownTippyRef.current.hide();
- handleUpdateAdditionalParam({
- paramType: activeTab,
- key: 'sendIn',
- paramIndex: index,
- value: 'body'
- })
- }}
- >
- Body
-
-
+ |
)}
-
+
-
+
)
}
-export default AdditionalParams;
\ No newline at end of file
+export default AdditionalParams;
+
+const Icon = forwardRef((props, ref) => {
+ const { value } = props
+ return (
+
+ );
+});
+
+const sendInOptionsMap = {
+ 'authorization_code': ['headers', 'queryparams'],
+ 'password': ['headers', 'queryparams', 'body'],
+ 'client_credentials': ['headers', 'queryparams', 'body']
+}
\ No newline at end of file
diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AuthorizationCode/index.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AuthorizationCode/index.js
index bc2feb019..5aadcd156 100644
--- a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AuthorizationCode/index.js
+++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/AuthorizationCode/index.js
@@ -34,7 +34,8 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
tokenQueryKey,
refreshTokenUrl,
autoRefreshToken,
- autoFetchToken
+ autoFetchToken,
+ additionalParameters
} = oAuth;
const refreshTokenUrlAvailable = refreshTokenUrl?.trim() !== '';
@@ -84,6 +85,7 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
refreshTokenUrl,
autoRefreshToken,
autoFetchToken,
+ additionalParameters,
[key]: value,
}
})
@@ -111,6 +113,7 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
tokenHeaderPrefix,
tokenQueryKey,
autoFetchToken,
+ additionalParameters,
pkce: !Boolean(oAuth?.['pkce'])
}
})
@@ -327,7 +330,7 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
-
+
);
diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/ClientCredentials/index.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/ClientCredentials/index.js
index 98b3e4607..f4b01135b 100644
--- a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/ClientCredentials/index.js
+++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/ClientCredentials/index.js
@@ -9,6 +9,7 @@ import { inputsConfig } from './inputsConfig';
import Dropdown from 'components/Dropdown';
import Oauth2TokenViewer from '../Oauth2TokenViewer/index';
import Oauth2ActionButtons from '../Oauth2ActionButtons/index';
+import AdditionalParams from '../AdditionalParams/index';
const OAuth2ClientCredentials = ({ save, item = {}, request, handleRun, updateAuth, collection }) => {
const dispatch = useDispatch();
@@ -30,7 +31,8 @@ const OAuth2ClientCredentials = ({ save, item = {}, request, handleRun, updateAu
tokenQueryKey,
refreshTokenUrl,
autoRefreshToken,
- autoFetchToken
+ autoFetchToken,
+ additionalParameters
} = oAuth;
const refreshTokenUrlAvailable = refreshTokenUrl?.trim() !== '';
@@ -77,6 +79,7 @@ const OAuth2ClientCredentials = ({ save, item = {}, request, handleRun, updateAu
refreshTokenUrl,
autoRefreshToken,
autoFetchToken,
+ additionalParameters,
[key]: value
}
})
@@ -295,7 +298,7 @@ const OAuth2ClientCredentials = ({ save, item = {}, request, handleRun, updateAu
-
+
diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/PasswordCredentials/index.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/PasswordCredentials/index.js
index 47f6fc5b2..086e10335 100644
--- a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/PasswordCredentials/index.js
+++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/PasswordCredentials/index.js
@@ -9,6 +9,7 @@ import { inputsConfig } from './inputsConfig';
import Dropdown from 'components/Dropdown';
import Oauth2TokenViewer from '../Oauth2TokenViewer/index';
import Oauth2ActionButtons from '../Oauth2ActionButtons/index';
+import AdditionalParams from '../AdditionalParams/index';
const OAuth2PasswordCredentials = ({ save, item = {}, request, handleRun, updateAuth, collection }) => {
const dispatch = useDispatch();
@@ -32,7 +33,8 @@ const OAuth2PasswordCredentials = ({ save, item = {}, request, handleRun, update
tokenQueryKey,
refreshTokenUrl,
autoRefreshToken,
- autoFetchToken
+ autoFetchToken,
+ additionalParameters
} = oAuth;
const refreshTokenUrlAvailable = refreshTokenUrl?.trim() !== '';
@@ -80,6 +82,7 @@ const OAuth2PasswordCredentials = ({ save, item = {}, request, handleRun, update
refreshTokenUrl,
autoRefreshToken,
autoFetchToken,
+ additionalParameters,
[key]: value
}
})
@@ -298,6 +301,7 @@ const OAuth2PasswordCredentials = ({ save, item = {}, request, handleRun, update
+
);
diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js
index 73049b918..256874730 100644
--- a/packages/bruno-app/src/utils/collections/index.js
+++ b/packages/bruno-app/src/utils/collections/index.js
@@ -1,8 +1,6 @@
import {cloneDeep, isEqual, sortBy, filter, map, isString, findIndex, find, each, get } from 'lodash';
import { uuid } from 'utils/common';
import path from 'utils/common/path';
-import brunoCommon from '@usebruno/common';
-const { interpolate } = brunoCommon;
const replaceTabsWithSpaces = (str, numSpaces = 2) => {
if (!str || !str.length || !isString(str)) {
@@ -650,7 +648,6 @@ export const transformRequestToSaveToFilesystem = (item) => {
json: replaceTabsWithSpaces(itemToSave.request.body.json)
};
}
-
return itemToSave;
};
diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js
index 7c84c7e8a..7e61afe45 100644
--- a/packages/bruno-lang/v2/src/bruToJson.js
+++ b/packages/bruno-lang/v2/src/bruToJson.js
@@ -1,6 +1,6 @@
const ohm = require('ohm-js');
const _ = require('lodash');
-const { safeParseJson, outdentString } = require('./utils');
+const { safeParseJson, outdentString, mergeOauth2AdditionalParameters } = require('./utils');
/**
* A Bru file is made up of blocks.
@@ -604,143 +604,43 @@ const sem = grammar.createSemantics().addAttribute('ast', {
};
},
oAuth2AuthorizationHeaders(_1, dictionary) {
- const authorizationHeaders = [...mapPairListToKeyValPairs(dictionary.ast)]?.map(_ => ({
- ..._,
- sendIn: 'headers'
- }));
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- authorization: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.authorization || []),
- ...authorizationHeaders
- ]
- }
- }
- }
+ oauth2_additional_parameters_authorization_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2AuthorizationQueryParams(_1, dictionary) {
- const authorizationQueryParams = [...mapPairListToKeyValPairs(dictionary.ast)]?.map(_ => ({
- ..._,
- sendIn: 'queryparams'
- }));
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- authorization: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.authorization || []),
- ...authorizationQueryParams
- ]
- }
- }
- }
+ oauth2_additional_parameters_authorization_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenHeaders(_1, dictionary) {
- const tokenHeaders = [...mapPairListToKeyValPairs(dictionary.ast)]?.map(_ => ({
- ..._,
- sendIn: 'headers'
- }));
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- token: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.token || []),
- ...tokenHeaders
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenQueryParams(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- tokenQueryParams: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.tokenQueryParams || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenBodyValues(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- tokenBodyValues: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.tokenBodyValues || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_bodyvalues: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshHeaders(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshHeaders: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshHeaders || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshQueryParams(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshQueryParams: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshQueryParams || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshBodyValues(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshBodyValues: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshBodyValues || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_bodyvalues: mapPairListToKeyValPairs(dictionary.ast)
};
},
authwsse(_1, dictionary) {
@@ -930,11 +830,14 @@ const parser = (input) => {
const match = grammar.match(input);
if (match.succeeded()) {
- return sem(match).ast;
+ let ast = sem(match).ast
+
+ ast = mergeOauth2AdditionalParameters(ast);
+
+ return ast;
} else {
throw new Error(match.message);
}
};
-module.exports = parser;
-
+module.exports = parser;
\ No newline at end of file
diff --git a/packages/bruno-lang/v2/src/collectionBruToJson.js b/packages/bruno-lang/v2/src/collectionBruToJson.js
index 4c49fc39f..029aa337b 100644
--- a/packages/bruno-lang/v2/src/collectionBruToJson.js
+++ b/packages/bruno-lang/v2/src/collectionBruToJson.js
@@ -1,6 +1,6 @@
const ohm = require('ohm-js');
const _ = require('lodash');
-const { safeParseJson, outdentString } = require('./utils');
+const { safeParseJson, outdentString, mergeOauth2AdditionalParameters } = require('./utils');
const grammar = ohm.grammar(`Bru {
BruFile = (meta | query | headers | auth | auths | vars | script | tests | docs | authOAuth2Configs)*
@@ -365,130 +365,42 @@ const sem = grammar.createSemantics().addAttribute('ast', {
},
oAuth2AuthorizationHeaders(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- authorizationHeaders: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.authorizationHeaders || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_authorization_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2AuthorizationQueryParams(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- authorizationQueryParams: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.authorizationQueryParams || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_authorization_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenHeaders(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- tokenHeaders: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.tokenHeaders || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenQueryParams(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- tokenQueryParams: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.tokenQueryParams || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2TokenBodyValues(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- tokenBodyValues: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.tokenBodyValues || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_token_bodyvalues: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshHeaders(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshHeaders: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshHeaders || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_headers: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshQueryParams(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshQueryParams: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshQueryParams || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_queryparams: mapPairListToKeyValPairs(dictionary.ast)
};
},
oAuth2RefreshBodyValues(_1, dictionary) {
return {
- auth: {
- oauth2: {
- ...(dictionary?.ast?.auth?.oauth2 || {}),
- additionalParameters: {
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters || {}),
- refreshBodyValues: [
- ...(dictionary?.ast?.auth?.oauth2?.additionalParameters?.refreshBodyValues || []),
- ...mapPairListToKeyValPairs(dictionary.ast)
- ]
- }
- }
- }
+ oauth2_additional_parameters_refresh_bodyvalues: mapPairListToKeyValPairs(dictionary.ast)
};
},
authwsse(_1, dictionary) {
@@ -594,7 +506,11 @@ const parser = (input) => {
const match = grammar.match(input);
if (match.succeeded()) {
- return sem(match).ast;
+ let ast = sem(match).ast;
+
+ ast = mergeOauth2AdditionalParameters(ast);
+
+ return ast;
} else {
throw new Error(match.message);
}
diff --git a/packages/bruno-lang/v2/src/jsonToBru.js b/packages/bruno-lang/v2/src/jsonToBru.js
index d8a7b13a3..0e848df41 100644
--- a/packages/bruno-lang/v2/src/jsonToBru.js
+++ b/packages/bruno-lang/v2/src/jsonToBru.js
@@ -251,31 +251,110 @@ ${indentString(`auto_refresh_token: ${(auth?.oauth2?.autoRefreshToken ?? false).
}
if (auth?.oauth2?.additionalParameters) {
- switch(auth?.oauth2?.additionalParameters) {
- case 'authorizationHeaders' :
- let authorizationHeaders = auth?.oauth2?.additionalParameters?.authorizationHeaders;
- bru += `auth:oauth2:authorization_headers {
-${enabled(authorizationHeaders)
- .map((item) => `${item.name}: ${item.value}`)
- .join('\n')}
-}`;
- break;
- case 'authorizationQueryParams' :
- let authorizationQueryParams = auth?.oauth2?.additionalParameters?.authorizationQueryParams;
- bru += `auth:oauth2:authorization_queryparams {
-${enabled(authorizationQueryParams)
- .map((item) => `${item.name}: ${item.value}`)
- .join('\n')}
-}`;
- break;
- case 'authorizationBodyValues' :
- let authorizationBodyValues = auth?.oauth2?.additionalParameters?.authorizationBodyValues;
- bru += `auth:oauth2:authorization_queryparams {
- ${enabled(authorizationBodyValues)
+ const { authorization: authorizationParams, token: tokenParams, refresh: refreshParams } = auth?.oauth2?.additionalParameters;
+ const authorizationHeaders = authorizationParams?.filter(p => p?.sendIn == 'headers');
+ if (authorizationHeaders?.length) {
+ bru += `auth:oauth2:authorization_headers {
+${indentString(
+ enabled(authorizationHeaders)
+ .filter(item => item?.name?.length)
.map((item) => `${item.name}: ${item.value}`)
- .join('\n')}
- }`;
- break;
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const authorizationQueryParams = authorizationParams?.filter(p => p?.sendIn == 'queryparams');
+ if (authorizationQueryParams?.length) {
+ bru += `auth:oauth2:authorization_queryparams {
+${indentString(
+ enabled(authorizationQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenHeaders = tokenParams?.filter(p => p?.sendIn == 'headers');
+ if (tokenHeaders?.length) {
+ bru += `auth:oauth2:token_headers {
+${indentString(
+ enabled(tokenHeaders)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenQueryParams = tokenParams?.filter(p => p?.sendIn == 'queryparams');
+ if (tokenQueryParams?.length) {
+ bru += `auth:oauth2:token_queryparams {
+${indentString(
+ enabled(tokenQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenBodyValues = tokenParams?.filter(p => p?.sendIn == 'body');
+ if (tokenBodyValues?.length) {
+ bru += `auth:oauth2:token_bodyvalues {
+${indentString(
+ enabled(tokenBodyValues)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshHeaders = refreshParams?.filter(p => p?.sendIn == 'headers');
+ if (refreshHeaders?.length) {
+ bru += `auth:oauth2:refresh_headers {
+${indentString(
+ enabled(refreshHeaders)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshQueryParams = refreshParams?.filter(p => p?.sendIn == 'queryparams');
+ if (refreshQueryParams?.length) {
+ bru += `auth:oauth2:refresh_queryparams {
+${indentString(
+ enabled(refreshQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshBodyValues = refreshParams?.filter(p => p?.sendIn == 'body');
+ if (refreshBodyValues?.length) {
+ bru += `auth:oauth2:refresh_bodyvalues {
+${indentString(
+ enabled(refreshBodyValues)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
}
}
}
diff --git a/packages/bruno-lang/v2/src/jsonToCollectionBru.js b/packages/bruno-lang/v2/src/jsonToCollectionBru.js
index 2812798a5..b1dbfd481 100644
--- a/packages/bruno-lang/v2/src/jsonToCollectionBru.js
+++ b/packages/bruno-lang/v2/src/jsonToCollectionBru.js
@@ -215,6 +215,114 @@ ${indentString(`auto_refresh_token: ${(auth?.oauth2?.autoRefreshToken ?? false).
`;
break;
}
+
+ if (auth?.oauth2?.additionalParameters) {
+ const { authorization: authorizationParams, token: tokenParams, refresh: refreshParams } = auth?.oauth2?.additionalParameters;
+ const authorizationHeaders = authorizationParams?.filter(p => p?.sendIn == 'headers');
+ if (authorizationHeaders?.length) {
+ bru += `auth:oauth2:authorization_headers {
+${indentString(
+ enabled(authorizationHeaders)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const authorizationQueryParams = authorizationParams?.filter(p => p?.sendIn == 'queryparams');
+ if (authorizationQueryParams?.length) {
+ bru += `auth:oauth2:authorization_queryparams {
+${indentString(
+ enabled(authorizationQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenHeaders = tokenParams?.filter(p => p?.sendIn == 'headers');
+ if (tokenHeaders?.length) {
+ bru += `auth:oauth2:token_headers {
+${indentString(
+ enabled(tokenHeaders)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenQueryParams = tokenParams?.filter(p => p?.sendIn == 'queryparams');
+ if (tokenQueryParams?.length) {
+ bru += `auth:oauth2:token_queryparams {
+${indentString(
+ enabled(tokenQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const tokenBodyValues = tokenParams?.filter(p => p?.sendIn == 'body');
+ if (tokenBodyValues?.length) {
+ bru += `auth:oauth2:token_bodyvalues {
+${indentString(
+ enabled(tokenBodyValues)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshHeaders = refreshParams?.filter(p => p?.sendIn == 'headers');
+ if (refreshHeaders?.length) {
+ bru += `auth:oauth2:refresh_headers {
+${indentString(
+ enabled(refreshHeaders)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshQueryParams = refreshParams?.filter(p => p?.sendIn == 'queryparams');
+ if (refreshQueryParams?.length) {
+ bru += `auth:oauth2:refresh_queryparams {
+${indentString(
+ enabled(refreshQueryParams)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ const refreshBodyValues = refreshParams?.filter(p => p?.sendIn == 'body');
+ if (refreshBodyValues?.length) {
+ bru += `auth:oauth2:refresh_bodyvalues {
+${indentString(
+ enabled(refreshBodyValues)
+ .filter(item => item?.name?.length)
+ .map((item) => `${item.name}: ${item.value}`)
+ .join('\n')
+ )}
+}
+
+`;
+ }
+ }
}
let reqvars = _.get(vars, 'req');
diff --git a/packages/bruno-lang/v2/src/utils.js b/packages/bruno-lang/v2/src/utils.js
index 74b22c952..5be1d225e 100644
--- a/packages/bruno-lang/v2/src/utils.js
+++ b/packages/bruno-lang/v2/src/utils.js
@@ -29,8 +29,83 @@ const outdentString = (str) => {
.join('\n');
};
+const mergeOauth2AdditionalParameters = (ast) => {
+ let additionalParameters = {};
+ const authorizationHeaders = ast?.oauth2_additional_parameters_authorization_headers;
+ const authorizationQueryParams = ast?.oauth2_additional_parameters_authorization_headers;
+ const tokenHeaders = ast?.oauth2_additional_parameters_token_headers;
+ const tokenQueryParams = ast?.oauth2_additional_parameters_token_queryparams;
+ const tokenBodyValues = ast?.oauth2_additional_parameters_token_bodyvalues;
+ const refreshHeaders = ast?.oauth2_additional_parameters_refresh_headers;
+ const refreshQueryParams = ast?.oauth2_additional_parameters_refresh_queryparams;
+ const refreshBodyValues = ast?.oauth2_additional_parameters_refresh_bodyvalues;
+
+ if (authorizationHeaders?.length || authorizationQueryParams?.length) {
+ additionalParameters['authorization'] = []
+ }
+ if (authorizationHeaders?.length) {
+ additionalParameters['authorization'] = [
+ ...authorizationHeaders?.map(_ => ({ ..._, sendIn: 'headers' }))
+ ]
+ }
+ if (authorizationQueryParams?.length) {
+ additionalParameters['authorization'] = [
+ ...authorizationQueryParams?.map(_ => ({ ..._, sendIn: 'queryparams' }))
+ ]
+ }
+
+ if (tokenHeaders?.length || tokenQueryParams?.length || tokenBodyValues?.length) {
+ additionalParameters['token'] = []
+ }
+ if (tokenHeaders?.length) {
+ additionalParameters['token'] = [
+ ...tokenHeaders?.map(_ => ({ ..._, sendIn: 'headers' }))
+ ]
+ }
+ if (tokenQueryParams?.length) {
+ additionalParameters['token'] = [
+ ...tokenQueryParams?.map(_ => ({ ..._, sendIn: 'queryparams' }))
+ ]
+ }
+ if (tokenBodyValues?.length) {
+ additionalParameters['token'] = [
+ ...tokenBodyValues?.map(_ => ({ ..._, sendIn: 'body' }))
+ ]
+ }
+
+ if (refreshHeaders?.length || refreshQueryParams?.length || refreshBodyValues?.length) {
+ additionalParameters['refresh'] = []
+ }
+ if (refreshHeaders?.length) {
+ additionalParameters['token'] = [
+ ...refreshHeaders?.map(_ => ({ ..._, sendIn: 'headers' }))
+ ]
+ }
+ if (refreshQueryParams?.length) {
+ additionalParameters['token'] = [
+ ...refreshQueryParams?.map(_ => ({ ..._, sendIn: 'queryparams' }))
+ ]
+ }
+ if (refreshBodyValues?.length) {
+ additionalParameters['token'] = [
+ ...refreshBodyValues?.map(_ => ({ ..._, sendIn: 'body' }))
+ ]
+ }
+
+ console.log("mergeee >>>>>", ast?.auth, ast?.auth?.oauth2, additionalParameters);
+
+ if(ast?.auth?.oauth2 && Object.keys(additionalParameters)?.length) {
+ ast.auth.oauth2.additionalParameters = additionalParameters;
+ }
+
+ console.log("mergeee >>>>>", ast?.auth);
+
+ return ast;
+}
+
module.exports = {
safeParseJson,
indentString,
- outdentString
+ outdentString,
+ mergeOauth2AdditionalParameters
};
diff --git a/packages/bruno-schema/src/collections/index.js b/packages/bruno-schema/src/collections/index.js
index 3914e6bfa..d59fafc32 100644
--- a/packages/bruno-schema/src/collections/index.js
+++ b/packages/bruno-schema/src/collections/index.js
@@ -157,6 +157,28 @@ const authApiKeySchema = Yup.object({
.noUnknown(true)
.strict();
+const oauth2AuthorizationAdditionalParametersSchema = Yup.object({
+ name: Yup.string().nullable(),
+ value: Yup.string().nullable(),
+ sendIn: Yup.string()
+ .oneOf(['headers', 'queryparams', 'body'])
+ .required('send in property is required'),
+ enabled: Yup.boolean()
+})
+ .noUnknown(true)
+ .strict();
+
+const oauth2AdditionalParametersSchema = Yup.object({
+ name: Yup.string().nullable(),
+ value: Yup.string().nullable(),
+ sendIn: Yup.string()
+ .oneOf(['headers', 'queryparams', 'body'])
+ .required('send in property is required'),
+ enabled: Yup.boolean()
+ })
+ .noUnknown(true)
+ .strict();
+
const oauth2Schema = Yup.object({
grantType: Yup.string()
.oneOf(['client_credentials', 'password', 'authorization_code'])
@@ -252,6 +274,11 @@ const oauth2Schema = Yup.object({
is: (val) => ['authorization_code'].includes(val),
then: Yup.boolean().default(true),
otherwise: Yup.boolean()
+ }),
+ additionalParameters: Yup.object({
+ authorization: Yup.array().of(oauth2AuthorizationAdditionalParametersSchema).optional(),
+ token: Yup.array().of(oauth2AdditionalParametersSchema).optional(),
+ refresh: Yup.array().of(oauth2AdditionalParametersSchema).optional()
})
})
.noUnknown(true)