react-keycloak-context
v1.0.7
Published
A Keycloak provider for React
Downloads
62
Maintainers
Readme
react-keycloak-context
A Keycloak provider for React
Table of Contents
Usage
import React from 'react'
import App, { Container } from 'next/app'
import Head from 'next/head'
import {
Provider as KeycloakProvider,
Consumer as KeycloakConsumer
} from 'react-keycloak-context'
const keycloakConfig = {
realm: 'master',
clientId: 'example',
url: 'https://foobarbaz.com/auth',
'ssl-required': 'external',
'public-client': true,
'confidential-port': 0
}
class Example extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps({ ...ctx })
}
return { pageProps }
}
handleKeycloakInit = kc => {
console.log('keycloak', kc)
}
render() {
const { Component, pageProps } = this.props
return (
<Container>
<Head>
<title>Example project</title>
</Head>
<KeycloakProvider
initOptions= {{
onLoad: 'login-required',
promiseType: 'native'
}}
config={keycloakConfig}
tokenKey={'kc-token'}
refreshTokenKey={'kc-refresh'}
onInit={this.handleKeycloakInit}
>
<KeycloakConsumer>
{kc => <Component keycloak={kc} {...pageProps} />}
</KeycloakConsumer>
</KeycloakProvider>
</Container>
)
}
}
export default Example
Install
This project uses node and npm.
$ npm install react-keycloak-context
$ # OR
$ yarn add react-keycloak-context
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT © [[object Object]]([object Object])