1.0.7 • Published 5 years ago

react-keycloak-context v1.0.7

Weekly downloads
41
License
MIT
Repository
github
Last release
5 years ago

react-keycloak-context

package version package downloads standard-readme compliant package license make a pull request

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

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT © [object Object](object Object)

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago