-
-
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.
feat: Implement OAuth 1.0 - collection level
- Loading branch information
1 parent
b1e3204
commit 9edd229
Showing
9 changed files
with
305 additions
and
3 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
20 changes: 20 additions & 0 deletions
20
packages/bruno-app/src/components/CollectionSettings/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,20 @@ | ||
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}; | ||
} | ||
.file-picker-wrapper { | ||
max-width: 400px; | ||
border-radius: 3px; | ||
} | ||
`; | ||
|
||
export default Wrapper; |
127 changes: 127 additions & 0 deletions
127
packages/bruno-app/src/components/CollectionSettings/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,127 @@ | ||
import React, { forwardRef, useCallback, useRef } from 'react'; | ||
import get from 'lodash/get'; | ||
import { useTheme } from 'providers/Theme'; | ||
import { useDispatch } from 'react-redux'; | ||
import SingleLineEditor from 'components/SingleLineEditor'; | ||
import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections'; | ||
import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions'; | ||
import StyledWrapper from './StyledWrapper'; | ||
import { inputsConfig } from './inputsConfig'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Dropdown from 'components/Dropdown'; | ||
import { IconCaretDown } from '@tabler/icons'; | ||
import FilePickerEditor from 'components/FilePickerEditor'; | ||
import path from 'path'; | ||
import { isWindowsOS } from 'utils/common/platform'; | ||
import slash from 'utils/common/slash'; | ||
|
||
const OAuth1 = ({ collection }) => { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
const { storedTheme } = useTheme(); | ||
|
||
const oAuth1 = get(collection, 'root.request.auth.oauth1', {}); | ||
|
||
const handleSave = () => dispatch(saveCollectionRoot(collection.uid)); | ||
|
||
const refs = useRef(new Map()); | ||
const setRef = useCallback((ref, key) => { | ||
if (ref) { | ||
refs.current.set(key, ref); | ||
} else { | ||
refs.current.delete(key); | ||
} | ||
}, []); | ||
|
||
const hideDropdown = (key) => { | ||
const dropdown = refs.current.get(key); | ||
if (dropdown?.hide) { | ||
dropdown.hide(); | ||
} | ||
}; | ||
|
||
const handleChange = (key, val) => { | ||
console.log(key, val); | ||
dispatch( | ||
updateCollectionAuth({ | ||
mode: 'oauth1', | ||
collectionUid: collection.uid, | ||
content: { | ||
...oAuth1, [key]: val | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
const relativeFile = (file) => { | ||
if (file) { | ||
if (isWindowsOS()) { | ||
return slash((path.win32.relative(collection.pathname, file))); | ||
} else { | ||
return path.posix.relative(collection.pathname, file); | ||
} | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
const optionDisplayName = (options, key) => { | ||
const option = (options.find(option => option.key === key)); | ||
return option?.label ? t(option.label) : key; | ||
}; | ||
|
||
return ( | ||
<StyledWrapper className="mt-2 flex w-full gap-4 flex-col"> | ||
{inputsConfig.map((input) => { | ||
const { key, label, type, options } = input; | ||
return ( | ||
<div className="flex flex-col w-full gap-1" key={`input-${key}`}> | ||
<label className="block font-medium">{t(label)}</label> | ||
{type === 'Dropdown' ? | ||
<div className="inline-flex items-center cursor-pointer grant-type-mode-selector w-fit"> | ||
<Dropdown icon={(<div | ||
className="flex items-center justify-end grant-type-label select-none">{optionDisplayName(options, oAuth1[key])} | ||
<IconCaretDown className="caret ml-1 mr-1" size={14} strokeWidth={2} /></div>)} | ||
onCreate={(ref) => setRef(ref, key)} | ||
placement="bottom-end" | ||
children={options.map((option) => ( | ||
<div | ||
className="dropdown-item" | ||
onClick={() => { | ||
hideDropdown(key); | ||
handleChange(key, option.key ? option.key : option); | ||
}}> | ||
{option.label ? t(option.label) : option} | ||
</div> | ||
))} | ||
/> | ||
</div> | ||
: ''} | ||
{type === 'SingleLineEditor' ? | ||
<div className="single-line-editor-wrapper"> | ||
<SingleLineEditor | ||
value={oAuth1[key] || ''} | ||
theme={storedTheme} | ||
onSave={handleSave} | ||
onChange={(val) => handleChange(key, val)} | ||
collection={collection} | ||
/> | ||
</div> | ||
: ''} | ||
{type === 'FilePickerEditor' ? | ||
<div className="file-picker-wrapper"> | ||
<FilePickerEditor | ||
value={[oAuth1[key]] || []} | ||
onChange={(val) => handleChange(key, relativeFile(val[0]))} | ||
collection={collection} | ||
/> | ||
</div> | ||
: ''} | ||
</div> | ||
); | ||
})} | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default OAuth1; |
79 changes: 79 additions & 0 deletions
79
packages/bruno-app/src/components/CollectionSettings/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,79 @@ | ||
const inputsConfig = [ | ||
{ | ||
key: 'consumerKey', | ||
label: 'AUTHORIZATION.OAUTH1.CONSUMER_KEY_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'consumerSecret', | ||
label: 'AUTHORIZATION.OAUTH1.CONSUMER_SECRET_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'requestTokenUrl', | ||
label: 'AUTHORIZATION.OAUTH1.REQUEST_TOKEN_URL_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'accessTokenUrl', | ||
label: 'AUTHORIZATION.OAUTH1.ACCESS_TOKEN_URL_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'authorizeUrl', | ||
label: 'AUTHORIZATION.OAUTH1.AUTHORIZE_URL_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'callbackUrl', | ||
label: 'AUTHORIZATION.OAUTH1.CALLBACK_TOKEN_URL_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'verifier', | ||
label: 'AUTHORIZATION.OAUTH1.OAUTH_VERIFIER_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'accessToken', | ||
label: 'AUTHORIZATION.OAUTH1.ACCESS_TOKEN_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'accessTokenSecret', | ||
label: 'AUTHORIZATION.OAUTH1.ACCESS_TOKEN_SECRET_FIELD', | ||
type: 'SingleLineEditor' | ||
}, | ||
{ | ||
key: 'rsaPrivateKey', | ||
label: 'AUTHORIZATION.OAUTH1.RSA_PRIVATE_KEY_FIELD', | ||
type: 'FilePickerEditor' | ||
}, | ||
{ | ||
key: 'signatureMethod', | ||
label: 'AUTHORIZATION.OAUTH1.SIGNATURE_METHOD_FIELD', | ||
type: 'Dropdown', | ||
options: ['HMAC-SHA1', 'HMAC-SHA256', 'HMAC-SHA512', 'RSA-SHA1', 'RSA-SHA256', 'RSA-SHA512', 'PLAINTEXT'] | ||
}, | ||
{ | ||
key: 'parameterTransmissionMethod', | ||
label: 'AUTHORIZATION.OAUTH1.PARAM_TRANSMISSION_METHOD_FIELD', | ||
type: 'Dropdown', | ||
options: [ | ||
{ | ||
key: 'authorization_header', | ||
label: 'AUTHORIZATION.OAUTH1.PARAM_TRANSMISSION_METHOD.AUTHORIZATION_HEADER' | ||
}, | ||
{ | ||
key: 'request_body', | ||
label: 'AUTHORIZATION.OAUTH1.PARAM_TRANSMISSION_METHOD.REQUEST_BODY' | ||
}, | ||
{ | ||
key: 'query_param', | ||
label: 'AUTHORIZATION.OAUTH1.PARAM_TRANSMISSION_METHOD.QUERY_PARAM' | ||
} | ||
] | ||
} | ||
]; | ||
|
||
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