This project is designed to handle authentication using OAuth2 with Hydra and OIDC. The project is divided into two phases:
- Phase 1: OAuth2 with Hydra
- Phase 2: OIDC Public Client (coming soon)
- Node.js (>= 14.x)
- npm (>= 6.x)
-
Clone the repository:
git clone https://github.com/your-username/auth-client.git cd auth-client
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
In this phase, we use OAuth2 with Hydra for authentication.
- Follow the Hydra documentation to set up Hydra in QA box environment.
- Configure your OAuth2 settings in the project.
Use the useOAuth2
hook within your components.
import React from 'react';
import { useOAuth2, TOAuth2EnabledAppList } from '@deriv-com/auth-client';
const YourComponent = () => {
const [OAuth2EnabledApps, OAuth2EnabledAppsInitialised] = useGrowthbookGetFeatureValue<TOAuth2EnabledAppList>({
featureFlag: 'hydra_be',
});
const { logout } = useAuthData(); // Your custom hook or function to handle logout
const OAuth2GrowthBookConfig = {
OAuth2EnabledApps,
OAuth2EnabledAppsInitialised
};
const WSLogoutAndRedirect = async () => {
await logout();
// Redirect or perform any additional actions here
};
const { OAuth2Logout } = useOAuth2(OAuth2GrowthBookConfig, WSLogoutAndRedirect);
return (
<div>
<button onClick={OAuth2Logout}>Logout</button>
</div>
);
};
export default YourComponent;
In this phase, we will transition to using an OIDC public client for authentication. Currently phase 1 is in development and OIDC public client will be implemented in the next phase.