1.4.0 ā€¢ Published 2 months ago

@cryptr/cryptr-react v1.4.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

šŸ“š @cryptr/cryptr-react

Cryptr SDK for React Single Page Applications using authentication (SSO, Magic link, password ... )

See Online documentation

Table of Content

Installation

Current version 1.4.0

//npm
npm install @cryptr/cryptr-react

//npm
yarn add @cryptr/cryptr-react

Configuration

CryptrConfig

Here is an example of a configuration that will be necessary to implement our solution

const config = {
  audience: process.env.REACT_APP_CRYPTR_AUDIENCE,
  cryptr_base_url: process.env.REACT_APP_CRYPTR_BASE_URL,
  tenant_domain: process.env.REACT_APP_CRYPTR_TENANT_DOMAIN,
  client_id: process.env.REACT_APP_CRYPTR_CLIENT_ID,
  default_redirect_uri: process.env.REACT_APP_CRYPTR_DEFAULT_REDIRECT_URI,
  dedicated_server: process.env.REACT_APP_CRYPTR_DEDICATED_SERVER == 'true',
  default_slo_after_revoke: process.env.REACT_APP_CRYPTR_DEFAULT_SLO_AFTER_REVOKE == 'true',
}

Explanation of config

keyRequired/OptionaltypeDefaultDescription
tenant_domainrequiredstring slug-Reference to your company entity
client_idrequireduuid-Reference to your front app id
audiencerequiredstring URL-Root URL of your front app
default_redirect_urirequiredstring URL-Desired redirection URL after authentication process
cryptr_base_urlrequiredstring URL-URL of your Cryptr service
default_slo_after_revokerequired(since 1.2.0)booleanDefines if SLO has to be done on SSO logout process
dedicated_serverOptionalbooleanfalseContact Cryptr Team to set properly

āš ļø fixed_pkce has been removed in the 1.4.0 release version

Cryptr Provider

After creating your config, create your CryptrProvider that should encapsulate your App content.

Here is a quick sample (also see our sample (src/examples/App.tsx))

import React, { ReactElement } from 'react'
import { BrowserRouter as Router, Route } from 'react-router-dom'

// import from cryptr SDK
import { CryptrProvider } from '@crypptr/cryptr-react'

const config = {/*... your config */}

const AppContainer = (): ReactElement => {
  return (
    <Router>
      // your routes
    </Router>
  )
}

const App = (): ReactElement => {
  <CryptrProvider {...config} >
    <AppContainer />
  </CryptrProvider>
}

return default App

Then you will be able to handle Cryptr session through our hook and our components

Cryptr Hook useCryptr

On any React element child of the CryptrProvider you'll be able to use our hook useCryptr for your Cryptr usage.

Here is a quick example

import React, { ReactElement } from 'react'
import { useCryptr } from '@cryptr/cryptr-react'

const MyComponent = (): ReactElement => {
  const { isAuthenticated, isLoading } = useCryptr()

  if (isLoading) {
    return <span>Cryptr is processing authentication</span>
  }

  if (isAuthenticated()) {
    return <span>A Cryptr session is live</span>
  } else {
    return <span>User is not authenticated</span>
  }
}

export default MyComponent

Here is a quick list of tools from our hook

NamePurpose
isLoadingCryptr SDK is currently looking for a active authentication (after login or refresh)
isAuthenticatedCryptr SDK has a live Access token āž”ļø a user is logged in
userReturns the user objecgt containing all keys from Cryptr ID Token
logOutAsks to Cryptr SDK to run the session log out process
decoratedRequest(axiosConfig: AxiosRequestConfig)This method based on axios will decorate the request to the desired endpoint with the current Access Token as Authorization Bearer Header

There are more but the major features are just above

Components

We embedded some components in this SDK to help your integration. Mainly it's button components and can still be configured as you wish (eg: text, className, style ...)

SignInWithDomainButton

When you either know which is the entity of the user trying to connect or if you prefer to let him type his email on our gateway

import React, { ReactElement } from 'react'
import { SignInWithDomainButton } from '@cryptr/cryptr-react'

const LoginComponent = (): ReactElement => {
  return <SignInWithDomainButton domain={'nullable-entity-domain'} />
}

export default LoginComponent

šŸ’” domain is optional if you do not know current user's context

SignInWithEmailButton

When you already asked the user his email address

import React, { ReactElement } from 'react'
import { SignInWithEmailButton } from '@cryptr/cryptr-react'

const LoginComponent = (): ReactElement => {
  return <SignInWithEmailButton email={'not-nullable-john@doe.com'} />
}

export default LoginComponent

Deprecations

Some legacy items have been deleted since 1.3.0. If you need some support for migration contact us

1.4.0

2 months ago

1.3.7

4 months ago

1.3.6

4 months ago

1.3.0

7 months ago

1.2.0

1 year ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.2

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.3-rc1

3 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.0-rc1

3 years ago

1.0.2-rc1

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago