-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4e5e9f
commit 96650ba
Showing
17 changed files
with
496 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/bruno-app/src/components/RequestPane/Auth/OAuth1/StyledWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import styled from 'styled-components'; | ||
|
||
const Wrapper = styled.div` | ||
label { | ||
font-size: 0.8125rem; | ||
} | ||
.single-line-editor-wrapper { | ||
max-width: 400px; | ||
padding: 0.15rem 0.4rem; | ||
border-radius: 3px; | ||
border: solid 1px ${(props) => props.theme.input.border}; | ||
background-color: ${(props) => props.theme.input.bg}; | ||
} | ||
`; | ||
|
||
export default Wrapper; |
82 changes: 82 additions & 0 deletions
82
packages/bruno-app/src/components/RequestPane/Auth/OAuth1/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useRef } from 'react'; | ||
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'; | ||
import { inputsConfig } from './inputsConfig'; | ||
import Dropdown from 'components/Dropdown'; | ||
|
||
const OAuth1 = ({ item, collection }) => { | ||
const dispatch = useDispatch(); | ||
const { storedTheme } = useTheme(); | ||
|
||
const oAuth1 = item.draft ? get(item, 'draft.request.auth.oauth1', {}) : get(item, 'request.auth.oauth1', {}); | ||
|
||
const handleRun = () => dispatch(sendRequest(item, collection.uid)); | ||
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid)); | ||
|
||
const dropdownTippyRef = useRef(); | ||
const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref); | ||
|
||
const handleChange = (key, val) => { | ||
console.log(key, val); | ||
dispatch( | ||
updateAuth({ | ||
mode: 'oauth1', | ||
collectionUid: collection.uid, | ||
itemUid: item.uid, | ||
content: { | ||
...oAuth1, [key]: val | ||
} | ||
}) | ||
); | ||
} | ||
|
||
return ( | ||
<StyledWrapper className="mt-2 flex w-full gap-4 flex-col"> | ||
{inputsConfig.map((input) => { | ||
const { key, label, options } = input; | ||
return ( | ||
<div className="flex flex-col w-full gap-1" key={`input-${key}`}> | ||
<label className="block font-medium">{label}</label> | ||
{options ? | ||
<div className="inline-flex items-center cursor-pointer grant-type-mode-selector w-fit"> | ||
<Dropdown icon={(<div>{ oAuth1[key] || '<select>'}</div>)} | ||
onCreate={onDropdownCreate} | ||
placement="bottom-end" | ||
children={options.map((option) => ( | ||
<div | ||
className="dropdown-item" | ||
onClick={() => { | ||
handleChange(key, option.key ? option.key : option); | ||
}}> | ||
{option.value ? option.value : option} | ||
</div> | ||
))} | ||
/> | ||
</div> | ||
|
||
: | ||
<div className="single-line-editor-wrapper"> | ||
<SingleLineEditor | ||
value={oAuth1[key] || ''} | ||
theme={storedTheme} | ||
onSave={handleSave} | ||
onChange={(val) => handleChange(key, val)} | ||
onRun={handleRun} | ||
collection={collection} | ||
item={item} | ||
/> | ||
</div> | ||
} | ||
</div> | ||
); | ||
})} | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default OAuth1; |
59 changes: 59 additions & 0 deletions
59
packages/bruno-app/src/components/RequestPane/Auth/OAuth1/inputsConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const inputsConfig = [ | ||
{ | ||
key: 'consumerKey', | ||
label: 'Consumer Key', | ||
}, | ||
{ | ||
key: 'consumerSecret', | ||
label: 'Consumer Secret' | ||
}, | ||
{ | ||
key: 'requestTokenUrl', | ||
label: 'Request Token URL' | ||
}, | ||
{ | ||
key: 'accessTokenUrl', | ||
label: 'Access Token URL' | ||
}, | ||
{ | ||
key: 'authorizeUrl', | ||
label: 'Authorize URL' | ||
}, | ||
{ | ||
key: 'callbackUrl', | ||
label: 'Callback URL' | ||
}, | ||
{ | ||
key: 'accessToken', | ||
label: 'Access Token' | ||
}, | ||
{ | ||
key: 'accessTokenSecret', | ||
label: 'Access Token Secret' | ||
}, | ||
{ | ||
key: 'authorizationMethod', | ||
label: 'Authorization Method', | ||
options: [ | ||
{ | ||
key: 'authorizationHeader', | ||
value: 'Authorization Header' | ||
}, | ||
{ | ||
key: 'requestBody', | ||
value: 'Request Body' | ||
}, | ||
{ | ||
key: 'queryParam', | ||
value: 'Query Parameter' | ||
} | ||
] | ||
}, | ||
{ | ||
key: 'signatureMethod', | ||
label: 'Signature Method', | ||
options: ['HMAC-SHA1', 'HMAC-SHA256', 'RSA-SHA1', 'PLAINTEXT'] | ||
} | ||
]; | ||
|
||
export { inputsConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.