New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@cryptr/cryptr-react

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cryptr/cryptr-react

Cryptr React Authentication SDK

Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
31
3.33%
Maintainers
2
Weekly downloads
 
Created
Source

📚 @cryptr/cryptr-react

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

See Online documentation See Online documentation

Table of Content

Installation

Current version 1.3.0

//npm
npm install @cryptr/cryptr-react

//npm
yarn add @cryptr/cryptr-react

Configuration

CryptrConfig

Here is an example of 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,
  default_locale: process.env.REACT_APP_CRYPTR_DEFAULT_LOCALE || 'en',
  telemetry: process.env.REACT_APP_CRYPTR_TELEMETRY == 'true',
  dedicated_server: process.env.REACT_APP_CRYPTR_DEDICATED_SERVER == 'true',
  fixed_pkce: process.env.REACT_APP_CRYPTR_FIXED_PKCE == '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
default_localeOptionalstring localeen-
dedicated_serverOptionalbooleanfalseContact Cryptr Team to set properly
fixed_pkceOptionalbooleanfalseContact Cryptr Team to set properly
telemetryOptionalbooleanfalseSet to true if debug

⚠️ fixed_pkce will be removed in the future 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 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

Since 1.3.0

Components

  • SignInButton -> SignInWithDomainButton
  • SignUpButton -> SignInWithDomainButton
  • SsoGatewayButton -> SignInWithDomainButton
  • SsoSignInButton -> SignInWithDomainButton

Cryptr Hooks

  • signinWithRedirect
  • signupWithRedirect
  • signinWithSSO
  • signinWithSSOGateway

Keywords

cryptr

FAQs

Package last updated on 10 Oct 2023

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