React client for custom OAuth2 implementations using spring-security-oauth2-authorization-server
npm install @authguard/react
React client for custom OAuth2 implementations using spring-security-oauth2-authorization-server.
First, install @authguard/react from npm:
``sh`
npm install @authguard/react
`sh`
yarn add @authguard/react
Now create a file authguard.ts in root directory:
`js
import { initializeAuthguard, Provider } from "@authguard/react";
export const authguardConfig = {
// Props
};
initializeAuthguard(authguardConfig);
export default Provider;
`
Below are the available props with their datatypes.
| Props | Type | |
| :---------------- | :------------------------------: | ---------: |
| oidc_url | String | _optional_ |
| jwks_url | String | _optional_ |
| token_url | String | _optional_ |
| redirect_url | String | _optional_ |
| authorize_url | String | _optional_ |
| user_info_url | String | _optional_ |
| refresh_token_url | String | _optional_ |
| revoke_token_url | String | _optional_ |
| grant | String | _optional_ |
| scope | String | _optional_ |
| credentials | Object (client_id,client_secret) | _optional_ |
To be able to use useAuthguard first you'll need to expose the authguard context,
`js`
`js`
The useAuthguard() React Hook in the client is the easiest way to check if someone is signed in.
`js``
import { useAuthguard } from "@authguard/react";
const { user, logout } = useAuthguard();
Follow links are some reference projects that have already setup authguard.
Authguard with React Application →
Authguard with Next JS Application →
This software is released under the MIT license. See LICENSE for more details.