Gathering detailed insights and metrics for @bitspur/react-keycloak-web
Gathering detailed insights and metrics for @bitspur/react-keycloak-web
Gathering detailed insights and metrics for @bitspur/react-keycloak-web
Gathering detailed insights and metrics for @bitspur/react-keycloak-web
React/React Native/NextJS/Razzle components for Keycloak
npm install @bitspur/react-keycloak-web
Typescript
Module System
Node Version
NPM Version
63.8
Supply Chain
91.2
Quality
75.7
Maintenance
100
Vulnerability
99.6
License
TypeScript (97.16%)
JavaScript (2.84%)
Total Downloads
2,488
Last Day
1
Last Week
1
Last Month
14
Last Year
419
MIT License
561 Stars
432 Commits
131 Forks
12 Watchers
3 Branches
10 Contributors
Updated on Dec 06, 2024
Minified
Minified + Gzipped
Latest Version
4.0.14
Package Id
@bitspur/react-keycloak-web@4.0.14
Unpacked Size
33.63 kB
Size
7.95 kB
File Count
33
NPM Version
9.5.1
Node Version
18.16.0
Published on
Jun 01, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-50%
1
Compared to previous week
Last Month
-72.5%
14
Compared to previous month
Last Year
-68.3%
419
Compared to previous year
4
React bindings for Keycloak
React Keycloak requires:
keycloak-js
9.0.2 or later1yarn add @react-keycloak/web
or
1npm install --save @react-keycloak/web
Create a keycloak.js
file in the src
folder of your project (where App.js
is located) with the following content
1import Keycloak from '@bitspur/keycloak-js' 2 3// Setup Keycloak instance as needed 4// Pass initialization options as required or leave blank to load from 'keycloak.json' 5const keycloak = new Keycloak() 6 7export default keycloak
Wrap your App inside ReactKeycloakProvider
and pass the keycloak
instance as prop
1import { ReactKeycloakProvider } from '@react-keycloak/web' 2 3import keycloak from './keycloak' 4 5// Wrap everything inside KeycloakProvider 6const App = () => { 7 return ( 8 <ReactKeycloakProvider authClient={keycloak}>...</ReactKeycloakProvider> 9 ) 10}
N.B. If your using other providers (such as react-redux
) it is recommended to place them inside ReactKeycloakProvider
.
ReactKeycloakProvider
automatically invokes keycloak.init()
method when needed and supports the following props:
initOptions
, contains the object to be passed to keycloak.init()
method, by default the following is used
{
onLoad: 'check-sso',
}
for more options see Keycloak docs.
LoadingComponent
, a component to be displayed while keycloak
is being initialized, if not provided child components will be rendered immediately. Defaults to null
isLoadingCheck
, an optional loading check function to customize LoadingComponent display condition. Return true
to display LoadingComponent, false
to hide it.
Can be implemented as follow
1;(keycloak) => !keycloak.authenticated
onEvent
, an handler function that receives events launched by keycloak
, defaults to null
.
It can be implemented as follow
1;(event, error) => { 2 console.log('onKeycloakEvent', event, error) 3}
Published events are:
onReady
onInitError
onAuthSuccess
onAuthError
onAuthRefreshSuccess
onAuthRefreshError
onTokenExpired
onAuthLogout
onTokens
, an handler function that receives keycloak
tokens as an object every time they change, defaults to null
.
Keycloak tokens are returned as follow
1{ 2 "idToken": string, 3 "refreshToken": string, 4 "token": string 5}
When a component requires access to Keycloak
, you can use the useKeycloak
Hook.
1import { useKeycloak } from '@react-keycloak/web' 2 3export default () => { 4 // Using Object destructuring 5 const { keycloak, initialized } = useKeycloak() 6 7 // Here you can access all of keycloak methods and variables. 8 // See https://www.keycloak.org/docs/latest/securing_apps/index.html#javascript-adapter-reference 9 10 return ( 11 <div> 12 <div>{`User is ${ 13 !keycloak.authenticated ? 'NOT ' : '' 14 }authenticated`}</div> 15 16 {!!keycloak.authenticated && ( 17 <button type="button" onClick={() => keycloak.logout()}> 18 Logout 19 </button> 20 )} 21 </div> 22 ) 23}
If you need to access keycloak
instance from non-React
files (such as sagas
, utils
, providers
...), you can import the instance directly from the keycloak.js
file.
The instance will be initialized by react-keycloak
but you'll need to be carefull when using the instance and avoid setting/overriding any props, you can however freely access the exposed methods (such as refreshToken
, login
, etc...).
See inside examples
folder of @react-keycloak/react-keycloak-examples
repository for various demo implementing this library main features.
Migration guide for @react-keycloak/web
v2.x to v3.x
can be found here MIGRATION.md.
Secure React Routes & Component with Keycloak, a (slightly outdated) guide on how to setup Keycloak
and create secured contents in a React
app, thanks to @cagline for the detailed article.
If you need to connect using a more generic OIDC client instead of keycloak.js
, consider using one of the following libraries:
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
If you found this project to be helpful, please consider buying me a coffee.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-12
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More