🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-keycloak-provider

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-keycloak-provider

[![tests](https://github.com/kantorv/react-keycloak-provider/actions/workflows/tests.yml/badge.svg)](https://github.com/kantorv/react-keycloak-provider/actions/workflows/tests.yml) [![npm](https://img.shields.io/npm/v/react-keycloak-provider.svg)](https:/

1.0.9
latest
Source
npm
Version published
Weekly downloads
19
-45.71%
Maintainers
0
Weekly downloads
 
Created
Source

React Keycloak Provider

tests npm

Based on keycloak-js package, wraps it with React Context Provider

usage

// providing
import { KeycloakProvider } from 'react-keycloak-provider';

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <KeycloakProvider
      // config={window.location.origin + '/keycloak.json'}
        
      // passed to constructor
      // const keycloak = new Keycloak({ ... })  
      config={{
         url: 'http://localhost:8282/',
         realm: 'demo',
         clientId: 'react-client'
      }}
        
      // passed to keycloak.init({ ... }) 
      initOptions={{
        // 'check-sso' or 'login-required'
        onLoad: 'check-sso',    
        // if  'check-sso' copy 'silent-check-sso.html' to /public folder
        silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html', 
      }}
    >
      <App />
    </KeycloakProvider>
  </React.StrictMode>
);

// consuming
import { useKeycloakContext } from 'react-keycloak-provider';
import Button from '@mui/material/Button';

const AppBar = ()=> {
    const {keycloak, authenticated} = useKeycloakContext();
    return (
        <div> 
            {authenticated? 
                <Button onClick={keycloak.logout} label="Logout" /> :  
                <Button onClick={keycloak.login} label="Login" />
            } 
        </div>
    )

};
<!-- silent-check-sso.html  -->
<html>
    <body>
        <script>
            parent.postMessage(location.href, location.origin)
        </script>
    </body>
</html>

References

Keywords

react

FAQs

Package last updated on 25 Sep 2024

Did you know?

Socket

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.

Install

Related posts