-
-
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.
OAuth2: Implement OAuth 2.0 Implicit Grant
- Loading branch information
1 parent
dce792a
commit ec20c66
Showing
21 changed files
with
466 additions
and
32 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
16 changes: 16 additions & 0 deletions
16
packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/Implicit/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,16 @@ | ||
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}; | ||
} | ||
`; | ||
|
||
export default Wrapper; |
86 changes: 86 additions & 0 deletions
86
packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/Implicit/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,86 @@ | ||
import React from 'react'; | ||
import get from 'lodash/get'; | ||
import { useTheme } from 'providers/Theme'; | ||
import { useDispatch } from 'react-redux'; | ||
import SingleLineEditor from 'components/SingleLineEditor'; | ||
import { saveCollectionRoot, sendCollectionOauth2Request } from 'providers/ReduxStore/slices/collections/actions'; | ||
import StyledWrapper from './StyledWrapper'; | ||
import { inputsConfig } from './inputsConfig'; | ||
import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections/index'; | ||
import { clearOauth2Cache } from 'utils/network'; | ||
import toast from 'react-hot-toast'; | ||
|
||
const OAuth2Implicit = ({ item, collection }) => { | ||
const dispatch = useDispatch(); | ||
const { storedTheme } = useTheme(); | ||
|
||
const oAuth = get(collection, 'root.request.auth.oauth2', {}); | ||
|
||
const handleRun = async () => { | ||
dispatch(sendCollectionOauth2Request(collection.uid)); | ||
}; | ||
|
||
const handleSave = () => dispatch(saveCollectionRoot(collection.uid)); | ||
|
||
const { callbackUrl, authorizationUrl, clientId, scope } = oAuth; | ||
|
||
const handleChange = (key, value) => { | ||
dispatch( | ||
updateCollectionAuth({ | ||
mode: 'oauth2', | ||
collectionUid: collection.uid, | ||
content: { | ||
grantType: 'implicit', | ||
callbackUrl, | ||
authorizationUrl, | ||
clientId, | ||
scope, | ||
[key]: value | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
const handleClearCache = (e) => { | ||
clearOauth2Cache(collection?.uid) | ||
.then(() => { | ||
toast.success('cleared cache successfully'); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.message); | ||
}); | ||
}; | ||
|
||
return ( | ||
<StyledWrapper className="mt-2 flex w-full gap-4 flex-col"> | ||
{inputsConfig.map((input) => { | ||
const { key, label } = input; | ||
return ( | ||
<div className="flex flex-col w-full gap-1" key={`input-${key}`}> | ||
<label className="block font-medium">{label}</label> | ||
<div className="single-line-editor-wrapper"> | ||
<SingleLineEditor | ||
value={oAuth[key] || ''} | ||
theme={storedTheme} | ||
onSave={handleSave} | ||
onChange={(val) => handleChange(key, val)} | ||
onRun={handleRun} | ||
collection={collection} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
<div className="flex flex-row gap-4"> | ||
<button onClick={handleRun} className="submit btn btn-sm btn-secondary w-fit"> | ||
Get Access Token | ||
</button> | ||
<button onClick={handleClearCache} className="submit btn btn-sm btn-secondary w-fit"> | ||
Clear Cache | ||
</button> | ||
</div> | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default OAuth2Implicit; |
20 changes: 20 additions & 0 deletions
20
packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/Implicit/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,20 @@ | ||
const inputsConfig = [ | ||
{ | ||
key: 'callbackUrl', | ||
label: 'Callback URL' | ||
}, | ||
{ | ||
key: 'authorizationUrl', | ||
label: 'Authorization URL' | ||
}, | ||
{ | ||
key: 'clientId', | ||
label: 'Client ID' | ||
}, | ||
{ | ||
key: 'scope', | ||
label: 'Scope' | ||
} | ||
]; | ||
|
||
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
16 changes: 16 additions & 0 deletions
16
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Implicit/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,16 @@ | ||
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}; | ||
} | ||
`; | ||
|
||
export default Wrapper; |
87 changes: 87 additions & 0 deletions
87
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Implicit/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,87 @@ | ||
import React from 'react'; | ||
import get from 'lodash/get'; | ||
import { useTheme } from 'providers/Theme'; | ||
import { useDispatch } from 'react-redux'; | ||
import SingleLineEditor from 'components/SingleLineEditor'; | ||
import { updateAuth } from 'providers/ReduxStore/slices/collections'; | ||
import { saveRequest, sendRequest } from 'providers/ReduxStore/slices/collections/actions'; | ||
import StyledWrapper from './StyledWrapper'; | ||
import { inputsConfig } from './inputsConfig'; | ||
import { clearOauth2Cache } from 'utils/network/index'; | ||
import toast from 'react-hot-toast'; | ||
|
||
const OAuth2Implicit = ({ item, collection }) => { | ||
const dispatch = useDispatch(); | ||
const { storedTheme } = useTheme(); | ||
|
||
const oAuth = item.draft ? get(item, 'draft.request.auth.oauth2', {}) : get(item, 'request.auth.oauth2', {}); | ||
|
||
const handleRun = async () => { | ||
dispatch(sendRequest(item, collection.uid)); | ||
}; | ||
|
||
const handleSave = () => dispatch(saveRequest(item.uid, collection.uid)); | ||
|
||
const { callbackUrl, authorizationUrl, clientId, scope } = oAuth; | ||
|
||
const handleChange = (key, value) => { | ||
dispatch( | ||
updateAuth({ | ||
mode: 'oauth2', | ||
collectionUid: collection.uid, | ||
itemUid: item.uid, | ||
content: { | ||
grantType: 'implicit', | ||
callbackUrl, | ||
authorizationUrl, | ||
clientId, | ||
scope, | ||
[key]: value | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
const handleClearCache = (e) => { | ||
clearOauth2Cache(collection?.uid) | ||
.then(() => { | ||
toast.success('cleared cache successfully'); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.message); | ||
}); | ||
}; | ||
|
||
return ( | ||
<StyledWrapper className="mt-2 flex w-full gap-4 flex-col"> | ||
{inputsConfig.map((input) => { | ||
const { key, label } = input; | ||
return ( | ||
<div className="flex flex-col w-full gap-1" key={`input-${key}`}> | ||
<label className="block font-medium">{label}</label> | ||
<div className="single-line-editor-wrapper"> | ||
<SingleLineEditor | ||
value={oAuth[key] || ''} | ||
theme={storedTheme} | ||
onSave={handleSave} | ||
onChange={(val) => handleChange(key, val)} | ||
onRun={handleRun} | ||
collection={collection} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
<div className="flex flex-row gap-4"> | ||
<button onClick={handleRun} className="submit btn btn-sm btn-secondary w-fit"> | ||
Get Access Token | ||
</button> | ||
<button onClick={handleClearCache} className="submit btn btn-sm btn-secondary w-fit"> | ||
Clear Cache | ||
</button> | ||
</div> | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default OAuth2Implicit; |
20 changes: 20 additions & 0 deletions
20
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Implicit/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,20 @@ | ||
const inputsConfig = [ | ||
{ | ||
key: 'callbackUrl', | ||
label: 'Callback URL' | ||
}, | ||
{ | ||
key: 'authorizationUrl', | ||
label: 'Authorization URL' | ||
}, | ||
{ | ||
key: 'clientId', | ||
label: 'Client ID' | ||
}, | ||
{ | ||
key: 'scope', | ||
label: 'Scope' | ||
} | ||
]; | ||
|
||
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
Oops, something went wrong.