Noncommital Premarital Mischief

    react-keycloak-context

    1.0.7 • Public • Published

    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]

    Install

    npm i react-keycloak-context

    DownloadsWeekly Downloads

    3

    Version

    1.0.7

    License

    MIT

    Unpacked Size

    10.7 kB

    Total Files

    12

    Last publish

    Collaborators

    • tiaanduplessis