Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@digital-wafa/react-keycloak
Advanced tools
a keycloak adapter for react with a protected route component that support react-router and reach-router
npm i @digital-wafa/react-keycloak
you should create an instance of keyclaok using the keycloak-js
package or importing the link from your keycloak server directly which is recommanded to avoid compatibily issues.
const keycloakInstance = new Keycloak({
url: "your keycloak url",
realm: "your realm",
clientId: "your client id",
....any other parameters
})
Then wrape your component with the keycloak provider, KeycloakProvider
accept the following props :
Props | Required | Description |
---|---|---|
keycloak | yes | the keycloak instance you created |
loginOptions | yes | the keycloak login options |
loadingComponent | only if you use the included ProtectedRoute component | the loading component to show when redirecting to keycloak login page |
import { KeycloakProvider } from "@digital-wafa/react-keycloak";
<KeycloakProvider
keycloak={keycloak}
loginOptions={{
idpHint: "ei",
scope: "phone",
}}
>
<App />
</KeycloakProvider>
finaly you can access the keycloak instance using the useKeycloakContext
hook which return the following object:
{
keycloak, // keycloak instance
loginOptions, // keycloak login options
authenticated // is the user authenticated or not
}
import { useKeycloakContext } from "@digital-wafa/react-keycloak";
const {keycloak, authenticated, loginOptions} = useKeycloakContext();
NB: the token is refreshed automatically when it expire using the onTokenExpired
event.
A useful component to protect your routes, it's compatible with react-router-dom
and @reach/router
if the user is authenticated, he will see the desired page, if not he will be redirected to the keycloak login page.
react-router-dom
example:
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { ProtectedRoute } from "@digital-wafa/react-keycloak";
<Router>
<ProtectedRoute
RouteComponent={Route}
ComponentToRender={YourPageComponent}
path="/your-path"
/>
<Router>
@reach/router
example:
when using @reach/router
you don't need to use the ComponentToRender
props
import { Router } from "@reach/router";
import { ProtectedRoute } from "@digital-wafa/react-keycloak";
<Router>
<ProtectedRoute
RouteComponent={YourPageComponent}
path="/your-path"
/>
<Router>
Get the tokens which are stored automatically in localStorage
after the login and the refreshToken actions.
To use outside your components
import { getToken, getRefreshToken } from "@digital-wafa/react-keycloak";
const token = getToken();
const refreshToken = getRefreshToken()
[1.0.1] - 2020-09-12
FAQs
a keycloak library for react
The npm package @digital-wafa/react-keycloak receives a total of 10 weekly downloads. As such, @digital-wafa/react-keycloak popularity was classified as not popular.
We found that @digital-wafa/react-keycloak demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.