forked from deriv-com/deriv-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request deriv-com#187 from thisyahlen-deriv/thisyahlen/oid…
…c-implementation-2 feat: oidc implementation
- Loading branch information
Showing
16 changed files
with
226 additions
and
34 deletions.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 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,2 @@ | ||
import CallbackPage from './CallbackPage'; | ||
export default CallbackPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { useEffect } from 'react'; | ||
import Layout from '@theme/Layout'; | ||
import CallbackPage from '../features/Callback'; | ||
const Callback = () => { | ||
useEffect(() => { | ||
const navbar = document.getElementsByClassName('navbar navbar--fixed-top')[0] as HTMLElement; | ||
if (navbar) { | ||
navbar.style.display = 'none'; | ||
} | ||
const metaTag = document.createElement('meta'); | ||
metaTag.name = 'robots'; | ||
metaTag.content = 'noindex, nofollow'; | ||
document.head.appendChild(metaTag); | ||
return () => { | ||
document.head.removeChild(metaTag); | ||
}; | ||
}, []); | ||
return ( | ||
<Layout title='Callback' description=''> | ||
<main> | ||
<CallbackPage /> | ||
</main> | ||
</Layout> | ||
); | ||
}; | ||
export default Callback; |
Oops, something went wrong.