-
Notifications
You must be signed in to change notification settings - Fork 19
feat: oidc implementation #176
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
Merged
shafin-deriv
merged 9 commits into
deriv-com:master
from
thisyahlen-deriv:thisyahlen/implement-oidc-logic
Dec 9, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
495b2fd
chore: oidc implementation
4a37d2c
chore: add callback page
e72d2a6
chore: add useHandleLogin hook
f7ff259
chore: use the hook in the login actions
5b31ad5
chore: add browseronly
56af47d
chore: update test
6fb270c
chore: make callback non crawlable on seo
4ab3280
chore: silent login and single logout
3e6c4ff
chore: test fix for logout
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
import React from 'react'; | ||
import { Callback } from '@deriv-com/auth-client'; | ||
import { transformAccountsFromResponseBody } from '@site/src/utils'; | ||
import useAuthContext from '@site/src/hooks/useAuthContext'; | ||
|
||
const CallbackPage = () => { | ||
const { updateLoginAccounts } = useAuthContext(); | ||
|
||
return ( | ||
<Callback | ||
onSignInSuccess={(tokens) => { | ||
const accounts = transformAccountsFromResponseBody(tokens); | ||
|
||
updateLoginAccounts(accounts); | ||
|
||
window.location.href = '/'; | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default CallbackPage; |
This file contains hidden or 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,3 @@ | ||
import CallbackPage from './CallbackPage'; | ||
|
||
export default CallbackPage; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
import useGrowthbookGetFeatureValue from '../useGrowthbookGetFeatureValue/'; | ||
import { | ||
requestOidcAuthentication, | ||
TOAuth2EnabledAppList, | ||
useIsOAuth2Enabled, | ||
} from '@deriv-com/auth-client'; | ||
|
||
/** | ||
* Handles the new login flow for the user using OIDC. | ||
* | ||
* If the user is not logged in and OAuth2 is enabled, it will redirect the user to the | ||
* OAuth2 authorization page from the OIDC config endpoint. If OAuth2 is not enabled it will | ||
* redirect the user to the legacy oauth url coming from the onClickLogin callback. | ||
* | ||
* @param {Object} props - The props object. | ||
* @param {Function} props.onClickLogin - The callback to be called when the user is logged in. | ||
* @returns {Object} - An object with the `handleLogin` function. | ||
*/ | ||
export const useHandleLogin = ({ onClickLogin }: { onClickLogin?: () => void }) => { | ||
const [OAuth2EnabledApps, OAuth2EnabledAppsInitialised] = | ||
useGrowthbookGetFeatureValue<TOAuth2EnabledAppList>({ | ||
featureFlag: 'hydra_be', | ||
}); | ||
|
||
const isOAuth2Enabled = useIsOAuth2Enabled(OAuth2EnabledApps, OAuth2EnabledAppsInitialised); | ||
|
||
const handleLogin = async () => { | ||
if (isOAuth2Enabled) { | ||
await requestOidcAuthentication({ | ||
redirectCallbackUri: `${window.location.origin}/callback`, | ||
}); | ||
} | ||
if (onClickLogin) { | ||
onClickLogin(); | ||
} | ||
}; | ||
|
||
return { handleLogin, isOAuth2Enabled }; | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.