Frontend OAuth with the Connect SDK

Build a React app that authenticates users with Humanity's OAuth flow and gates content based on biometric verification — using the Connect SDK directly without pre-built components.

circle-info

This guide uses the sandbox environment.

Build a React app that authenticates users with Humanity's OAuth and gates access based on the isHuman biometric credential.

The Connect SDK gives you three core methods that you can use to control the flow with no pre-built components or abstraction layer.

After this guide you'll have:

  • A working Vite + React app that runs locally

  • The complete OAuth + PKCE flow wired up yourself

  • Biometric credential verification with live status display

  • A full sandbox test using mock credentials

Use this approach if you want granular control over authentication, need to understand the flow before abstracting it, or are building a custom integration.

Full source

Before you start

You need:

If you haven't registered an application yet, follow the Developer Portal setup guidearrow-up-right first. You'll need your clientId and redirectUri.

01. Create the project

Create package.json:

Install dependencies:

circle-info

The Connect SDK uses Node.js APIs (crypto, buffer, stream) internally.

In browser environments, these must be polyfilled. The vite-plugin-node-polyfills package handles this automatically.

Create vite.config.ts:

Create tsconfig.json:

Create tsconfig.app.json:

Create tsconfig.node.json:

Create index.html at the project root:

02. Configure the Developer Portal

Go to developers.humanity.orgarrow-up-right, open your application, and switch to the Sandbox tab in Settings.

  • Add http://localhost:5173/oauth/callback as a redirect URI

  • Under scopes, enable:

    • OpenID Connect (openid) — required for the OAuth flow

    • Identity Information (identity:read) — includes Palm Verified credential

03. Generate a sandbox credential

Before testing the flow, generate a mock Palm Vein Biometric Scan credential in the Sandbox Dashboard.

  1. Open the Create tab

  2. Search for Palm Vein and select it

04. Set up environment variables

Create .env.local at the project root:

Get these values from the Developer Portal under your application's sandbox settings.

circle-exclamation

05. Build the app

Create the folder structure:

SDK initialization — src/lib/humanity.ts

Initialize the Connect SDK with your credentials. Store and retrieve the PKCE code verifier in session storage.

Auth context — src/hooks/useAuth.tsx

This context holds your access token, credentials, and metadata. Session storage keeps everything across page reloads during testing.

Button component — src/components/Button.tsx

A reusable button with multiple style variants.

Login button — src/components/LoginButton.tsx

This generates the SDK auth URL with PKCE and stores the code verifier before redirecting to Humanity.

Home page — src/pages/Home.tsx

Display the verification card and redirect authenticated users to the dashboard.

OAuth callback — src/pages/OAuthCallback.tsx

This page handles the redirect back from Humanity. It exchanges your authorization code for an access token and checks for the is_human credential.

Dashboard — src/pages/Dashboard.tsx

Display the biometric status. The is_human credential can be true, false, or missing—the dashboard shows all three.

App routing — src/App.tsx

Entry point — src/main.tsx

Stylesheet — src/index.css

The app uses a plain CSS stylesheet — no Tailwind. All component classes (biometric-status-card, dashboard-shell, home-screen, etc.) and the utility classes used throughout the components are defined here.

06. Run and test

Start the dev server:

Open http://localhost:5173. You should see the home page with a "Verify" button.

  1. Click Verify

  2. Sign in with your sandbox account (the one with the mock is_human credential)

  3. You'll land on the dashboard showing Human verified

If you test without a credential, the dashboard shows Not verified with value false or missing.

How it works

The whole flow comes down to three SDK methods:

  1. buildAuthUrl() — creates an authorization URL with PKCE. Store the code verifier in session storage.

  2. exchangeCodeForToken() — swaps the authorization code for an access token using the stored verifier.

  3. verifyPresets() — checks which credentials the user has. In this case, just is_human.

The app keeps tokens and credential data in session storage. On the dashboard, it pulls out the is_human through isHuman mapping value and displays the result.

Next Steps

Ready to build a more complex application?

The Personalized Newsletter Apparrow-up-right takes everything you built here and moves it to a full-stack Next.js setup — tokens handled server-side, clientSecret kept out of the browser, and session storage replaced with HTTP-only cookies.

You'll work with batch preset verification, the Query Engine, and MongoDB to build something that actually acts on verified identity: a personalized content feed driven by what Humanity knows about the user.

Last updated