-
-
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: OAuth 2.0 Client Credentials Basic Auth #2164
Open
pietrygamat
wants to merge
4
commits into
usebruno:fix/oauth2
Choose a base branch
from
pietrygamat:feature/oauth2-basic-auth
base: fix/oauth2
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
4 commits
Select commit
Hold shift + click to select a range
5fe4e69
feat: OAuth2 - Client Credentials as Basic Auth Header - bru data model
pietrygamat c055a43
feat: OAuth2 - Client Credentials as Basic Auth Header - request logic
pietrygamat b312193
feat: OAuth2 - Client Credentials as Basic Auth Header - user interface
pietrygamat f434d63
feat: OAuth2 - Client Credentials as Basic Auth Header - update test …
pietrygamat 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
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
25 changes: 25 additions & 0 deletions
25
...p/src/components/RequestPane/Auth/OAuth2/ClientCredentialsMethodSelector/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,25 @@ | ||
import styled from 'styled-components'; | ||
|
||
const Wrapper = styled.div` | ||
font-size: 0.8125rem; | ||
|
||
.client-credentials-secret-mode-selector { | ||
padding: 0.5rem 0px; | ||
border-radius: 3px; | ||
border: solid 1px ${(props) => props.theme.input.border}; | ||
background-color: ${(props) => props.theme.input.bg}; | ||
|
||
.client-credentials-secret-label { | ||
width: fit-content; | ||
color: ${(props) => props.theme.colors.text.yellow}; | ||
justify-content: space-between; | ||
padding: 0 0.5rem; | ||
} | ||
|
||
.dropdown-item { | ||
padding: 0.2rem 0.6rem !important; | ||
} | ||
} | ||
`; | ||
|
||
export default Wrapper; |
82 changes: 82 additions & 0 deletions
82
...bruno-app/src/components/RequestPane/Auth/OAuth2/ClientCredentialsMethodSelector/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, { forwardRef, useEffect, useRef } from 'react'; | ||
import Dropdown from 'components/Dropdown'; | ||
import StyledWrapper from './StyledWrapper'; | ||
import { IconCaretDown } from '@tabler/icons'; | ||
import { updateAuth, updateCollectionAuth } from 'providers/ReduxStore/slices/collections'; | ||
import { useDispatch } from 'react-redux'; | ||
import { humanizeOAuth2ClientSecretMethod } from 'utils/collections'; | ||
|
||
const ClientCredentialsMethodSelector = ({ item, collection, oAuth }) => { | ||
const clientSecretMethods = ['client_credentials_basic', 'client_credentials_post']; | ||
|
||
const dispatch = useDispatch(); | ||
const dropDownRef = useRef(); | ||
const onDropdownCreate = (ref) => (dropDownRef.current = ref); | ||
|
||
const Icon = forwardRef((props, ref) => { | ||
return ( | ||
<div ref={ref} className="flex items-center justify-end client-credentials-secret-label select-none"> | ||
{humanizeOAuth2ClientSecretMethod(oAuth?.clientSecretMethod)}{' '} | ||
<IconCaretDown className="caret ml-1 mr-1" size={14} strokeWidth={2} /> | ||
</div> | ||
); | ||
}); | ||
|
||
const onClientSecretMethodChange = (clientSecretMethod) => { | ||
if (item) { | ||
// Update request level authentication | ||
dispatch( | ||
updateAuth({ | ||
mode: 'oauth2', | ||
collectionUid: collection.uid, | ||
itemUid: item.uid, | ||
content: { | ||
...oAuth, | ||
clientSecretMethod: clientSecretMethod | ||
} | ||
}) | ||
); | ||
} else { | ||
// Update collection level authentication | ||
dispatch( | ||
updateCollectionAuth({ | ||
mode: 'oauth2', | ||
collectionUid: collection.uid, | ||
content: { | ||
...oAuth, | ||
clientSecretMethod: clientSecretMethod | ||
} | ||
}) | ||
); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
!oAuth?.clientSecretMethod && onClientSecretMethodChange(clientSecretMethods[0]); | ||
}, [oAuth.clientSecretMethod]); | ||
|
||
return ( | ||
<StyledWrapper> | ||
<label className="block font-medium mb-2">Send Client Credentials</label> | ||
<div className="inline-flex items-center cursor-pointer client-credentials-secret-mode-selector w-fit"> | ||
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end"> | ||
{clientSecretMethods.map((item, index) => ( | ||
<div | ||
key={item} | ||
className="dropdown-item" | ||
onClick={() => { | ||
dropDownRef.current.hide(); | ||
onClientSecretMethodChange(item); | ||
}} | ||
> | ||
{' '} | ||
{humanizeOAuth2ClientSecretMethod(item)} | ||
{index === 0 ? ` (Default)` : ``} | ||
</div> | ||
))} | ||
</Dropdown> | ||
</div> | ||
</StyledWrapper> | ||
); | ||
}; | ||
export default ClientCredentialsMethodSelector; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ export const moveCollectionItemToRootOfCollection = (collection, draggedItem) => | |
draggedItemParent.items = filter(draggedItemParent.items, (i) => i.uid !== draggedItem.uid); | ||
collection.items = sortBy(collection.items, (item) => item.seq); | ||
collection.items.push(draggedItem); | ||
if (draggedItem.type == 'folder') { | ||
if (draggedItem.type === 'folder') { | ||
draggedItem.pathname = path.join(collection.pathname, draggedItem.name); | ||
} else { | ||
draggedItem.pathname = path.join(collection.pathname, draggedItem.filename); | ||
|
@@ -733,6 +733,22 @@ export const humanizeGrantType = (mode) => { | |
return label; | ||
}; | ||
|
||
export const humanizeOAuth2ClientSecretMethod = (mode) => { | ||
let label = 'N/A'; | ||
switch (mode) { | ||
case 'client_credentials_basic': { | ||
label = 'As Basic Auth Header'; | ||
break; | ||
} | ||
case 'client_credentials_post': { | ||
label = 'In Request Body'; | ||
break; | ||
} | ||
} | ||
|
||
return label; | ||
}; | ||
Comment on lines
+736
to
+750
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: move to i18n/translation, but this should best be done in separate PR |
||
|
||
export const refreshUidsInItem = (item) => { | ||
item.uid = uuid(); | ||
|
||
|
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.
The same component is used in
RequestPane
and inCollectionSettings/Auth
. While the convention in the project seems to be using duplicate, almost identical components, I feel this approach is easier to manage. Perhaps it should be moved into a different location then?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.
seconded - perhaps we should have a
shared
components directory