-
-
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: OAuth 2.0 Client Credentials as Basic Auth - user interface
- Loading branch information
1 parent
3302156
commit cd0b2be
Showing
9 changed files
with
151 additions
and
6 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
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