-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement OAuth1 authorization method #2989
Open
pietrygamat
wants to merge
3
commits into
usebruno:main
Choose a base branch
from
pietrygamat:feature/1004/oauth1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these inputs are required to fill (consumer key/secret), and some will be filled by Bruno during execution if found empty (verifier, access token). Some will only make sense under certain conditions (rsa-private key is only needed when using RSA signing method, but then it's mandatory).
The UX improvements like hints or auto-disabling controls depending on other choices may be introduced in the future, but I guess it's better left out of this PR.