mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-02 08:58:32 +00:00
wip: oauth2 additional parameters
This commit is contained in:
@@ -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;
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="tabs">
|
||||
<div className="tab">Authorization</div>
|
||||
<div className="tab">Token</div>
|
||||
<div className="tab">Refresh</div>
|
||||
<StyledWrapper className="mt-4">
|
||||
<div className="tabs flex w-full gap-2 my-2">
|
||||
<div className={`tab ${activeTab == 'authorization' ? 'active': ''}`} onClick={e => setActiveTab('authorization')}>Authorization</div>
|
||||
<div className={`tab ${activeTab == 'token' ? 'active': ''}`} onClick={e => setActiveTab('token')}>Token</div>
|
||||
<div className={`tab ${activeTab == 'refresh' ? 'active': ''}`} onClick={e => setActiveTab('refresh')}>Refresh</div>
|
||||
</div>
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="py-2 px-4 font-semibold w-32">Key</th>
|
||||
<th className="py-2 px-4 font-semibold w-32">Value</th>
|
||||
<th className="py-2 px-4 font-semibold w-32">Send In</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<Table
|
||||
headers={[
|
||||
{ name: 'Key', accessor: 'name', width: '30%' },
|
||||
{ name: 'Value', accessor: 'value', width: '30%' },
|
||||
{ name: 'Sends In', accessor: 'sendIn', width: '150px' },
|
||||
{ name: '', accessor: '', width: '15%' }
|
||||
]}
|
||||
>
|
||||
<tbody>
|
||||
{additionalParams?.[activeTab]?.map((param, index) =>
|
||||
{additionalParameters?.[activeTab]?.map((param, index) =>
|
||||
<tr>
|
||||
<td>
|
||||
<td className='flex relative'>
|
||||
<SingleLineEditor
|
||||
value={param?.name}
|
||||
theme={storedTheme}
|
||||
onSave={handleSave}
|
||||
// onSave={handleSave}
|
||||
onChange={(value) => handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'name',
|
||||
@@ -148,7 +98,7 @@ const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
|
||||
<SingleLineEditor
|
||||
value={param?.value}
|
||||
theme={storedTheme}
|
||||
onSave={handleSave}
|
||||
// onSave={handleSave}
|
||||
onChange={(value) => handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'value',
|
||||
@@ -158,59 +108,86 @@ const AdditionalParams = ({ item = {}, request, updateAuth, collection }) => {
|
||||
collection={collection}
|
||||
/>
|
||||
</td>
|
||||
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={() => {
|
||||
dropdownTippyRef.current.hide();
|
||||
handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'sendIn',
|
||||
paramIndex: index,
|
||||
value: 'header'
|
||||
})
|
||||
}}
|
||||
>
|
||||
Header
|
||||
<td>
|
||||
<div className="w-full additional-parameter-sends-in-selector">
|
||||
<select
|
||||
value={param?.sendIn}
|
||||
onChange={e => {
|
||||
handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'sendIn',
|
||||
paramIndex: index,
|
||||
value: e.target.value
|
||||
})
|
||||
}}
|
||||
className="mousetrap bg-transparent"
|
||||
>
|
||||
{sendInOptionsMap[grantType].map((optionValue) => (
|
||||
<option key={optionValue} value={optionValue}>
|
||||
{optionValue}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={() => {
|
||||
dropdownTippyRef.current.hide();
|
||||
handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'sendIn',
|
||||
paramIndex: index,
|
||||
value: 'queryparams'
|
||||
})
|
||||
}}
|
||||
>
|
||||
Query Params
|
||||
</td>
|
||||
<td>
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={param?.enabled}
|
||||
tabIndex="-1"
|
||||
className="mr-3 mousetrap"
|
||||
onChange={(e) => {
|
||||
handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'enabled',
|
||||
paramIndex: index,
|
||||
value: e.target.checked
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
tabIndex="-1"
|
||||
onClick={() => {
|
||||
handleDeleteAdditionalParam({
|
||||
paramType: activeTab,
|
||||
paramIndex: index
|
||||
})
|
||||
}}
|
||||
>
|
||||
<IconTrash strokeWidth={1.5} size={20} />
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={() => {
|
||||
dropdownTippyRef.current.hide();
|
||||
handleUpdateAdditionalParam({
|
||||
paramType: activeTab,
|
||||
key: 'sendIn',
|
||||
paramIndex: index,
|
||||
value: 'body'
|
||||
})
|
||||
}}
|
||||
>
|
||||
Body
|
||||
</div>
|
||||
</Dropdown>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</Table>
|
||||
<div className="add-additional-param-actions">
|
||||
<IconPlus size={16} strokeWidth={1.5} style={{ marginLeft: '2px' }} onClick={handleAddNewAdditionalParam} />
|
||||
</div>
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
export default AdditionalParams;
|
||||
export default AdditionalParams;
|
||||
|
||||
const Icon = forwardRef((props, ref) => {
|
||||
const { value } = props
|
||||
return (
|
||||
<div ref={ref} className="w-max textbox border p-2 rounded cursor-pointer flex items-center selector-label">
|
||||
<div className="flex-grow font-medium">
|
||||
{value}
|
||||
</div>
|
||||
<div>
|
||||
<IconCaretDown className="caret mx-2" size={14} strokeWidth={2} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const sendInOptionsMap = {
|
||||
'authorization_code': ['headers', 'queryparams'],
|
||||
'password': ['headers', 'queryparams', 'body'],
|
||||
'client_credentials': ['headers', 'queryparams', 'body']
|
||||
}
|
||||
@@ -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
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<AdditionalParams item={item} request={request} collection={collection} url={accessTokenUrl} />
|
||||
<AdditionalParams item={item} request={request} collection={collection} url={accessTokenUrl} updateAuth={updateAuth} />
|
||||
<Oauth2ActionButtons item={item} request={request} collection={collection} url={accessTokenUrl} credentialsId={credentialsId} />
|
||||
</StyledWrapper>
|
||||
);
|
||||
|
||||
@@ -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
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AdditionalParams item={item} request={request} collection={collection} url={accessTokenUrl} updateAuth={updateAuth} />
|
||||
<Oauth2ActionButtons item={item} request={request} collection={collection} url={accessTokenUrl} credentialsId={credentialsId} />
|
||||
|
||||
</StyledWrapper>
|
||||
|
||||
@@ -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
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<AdditionalParams item={item} request={request} collection={collection} url={accessTokenUrl} updateAuth={updateAuth} />
|
||||
<Oauth2ActionButtons item={item} request={request} collection={collection} url={accessTokenUrl} credentialsId={credentialsId} />
|
||||
</StyledWrapper>
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
)}
|
||||
}
|
||||
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user