Gathering detailed insights and metrics for @react-keycloak/web
Gathering detailed insights and metrics for @react-keycloak/web
Gathering detailed insights and metrics for @react-keycloak/web
Gathering detailed insights and metrics for @react-keycloak/web
React/React Native/NextJS/Razzle components for Keycloak
npm install @react-keycloak/web
Typescript
Module System
Node Version
NPM Version
83.5
Supply Chain
94.5
Quality
78.4
Maintenance
100
Vulnerability
99.6
License
TypeScript (97.16%)
JavaScript (2.84%)
Total Downloads
10,107,868
Last Day
2,774
Last Week
70,484
Last Month
290,812
Last Year
3,229,022
561 Stars
432 Commits
132 Forks
13 Watching
3 Branches
10 Contributors
Latest Version
3.4.0
Package Id
@react-keycloak/web@3.4.0
Size
8.92 kB
NPM Version
lerna/3.22.1/node@v12.18.4+x64 (darwin)
Node Version
12.18.4
Publised On
21 Oct 2020
Cumulative downloads
Total Downloads
Last day
-11.5%
2,774
Compared to previous day
Last week
-9.1%
70,484
Compared to previous week
Last month
-3.4%
290,812
Compared to previous month
Last year
8.9%
3,229,022
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 '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 <ReactKeycloakProvider authClient={keycloak}>...</ReactKeycloakProvider> 8}
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.
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 dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
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 2024-12-16
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