-
-
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.
Merge branch 'pietrygamat/inherit-oauth' into HEAD
- Loading branch information
Showing
20 changed files
with
264 additions
and
175 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
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
17 changes: 17 additions & 0 deletions
17
...ages/bruno-app/src/components/RequestPane/Auth/OAuth2/CredentialsPreview/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,17 @@ | ||
import styled from 'styled-components'; | ||
|
||
const Wrapper = styled.div` | ||
label { | ||
display: block; | ||
font-size: 0.8125rem; | ||
} | ||
textarea { | ||
height: fit-content; | ||
max-width: 400px; | ||
border: solid 1px ${(props) => props.theme.input.border}; | ||
background-color: ${(props) => props.theme.input.bg}; | ||
} | ||
`; | ||
|
||
export default Wrapper; |
80 changes: 80 additions & 0 deletions
80
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/CredentialsPreview/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,80 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { clearOauth2Cache, readOauth2CachedCredentials } from 'utils/network'; | ||
import { sendCollectionOauth2Request, sendRequest } from 'providers/ReduxStore/slices/collections/actions'; | ||
import toast from 'react-hot-toast'; | ||
import { useDispatch } from 'react-redux'; | ||
import StyledWrapper from './StyledWrapper'; | ||
|
||
const CredentialsPreview = ({ item, collection }) => { | ||
const oauth2CredentialsAreaRef = React.createRef(); | ||
const [oauth2Credentials, setOauth2Credentials] = useState({}); | ||
|
||
const dispatch = useDispatch(); | ||
useEffect(() => { | ||
oauth2CredentialsAreaRef.current.value = oauth2Credentials; | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => setOauth2Credentials(credentials)); | ||
}, [oauth2CredentialsAreaRef]); | ||
|
||
const handleRun = async () => { | ||
if (item) { | ||
dispatch(sendRequest(item, collection.uid)); | ||
} else { | ||
dispatch(sendCollectionOauth2Request(collection.uid)); | ||
} | ||
}; | ||
|
||
const handleClearCache = (e) => { | ||
clearOauth2Cache(collection?.uid) | ||
.then(() => { | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => { | ||
setOauth2Credentials(credentials); | ||
toast.success('Cleared cache successfully'); | ||
}); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.message); | ||
}); | ||
}; | ||
|
||
const sortedFields = () => { | ||
const tokens = {}; | ||
const extras = {}; | ||
Object.entries(oauth2Credentials).forEach(([key, value]) => { | ||
if (key.endsWith('_token')) { | ||
tokens[key] = value; | ||
} else { | ||
extras[key] = value; | ||
} | ||
}); | ||
return { ...tokens, ...extras }; | ||
}; | ||
|
||
return ( | ||
<StyledWrapper className="flex flex-col w-full gap-1 mt-4"> | ||
<div className="credential-item-wrapper" ref={oauth2CredentialsAreaRef}> | ||
{Object.entries(oauth2Credentials).length > 0 ? ( | ||
<> | ||
<button onClick={handleClearCache} className="submit btn btn-sm btn-secondary w-fit"> | ||
Clear Access Token Cache | ||
</button> | ||
<details className="cursor-pointer flex flex-row w-full mt-2 gap-2"> | ||
<summary>Cached OAuth2 Credentials</summary> | ||
{Object.entries(sortedFields()).map(([field, value]) => ( | ||
<div key={field}> | ||
<label className="text-xs">{field}</label> | ||
<textarea className="w-full h-24 p-2 text-xs border rounded" value={value} readOnly /> | ||
</div> | ||
))} | ||
</details> | ||
</> | ||
) : ( | ||
<button onClick={handleRun} className="submit btn btn-sm btn-secondary w-fit"> | ||
Get Access Token | ||
</button> | ||
)} | ||
</div> | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default CredentialsPreview; |
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.