Skip to content

@udibo/oauth2

OAuth2 and OpenID Connect tools for TypeScript applications. Connect your app to Udibo's identity service, or host an authorization server for your own app. The package includes clients, authorization and resource servers, Hono middleware, React bindings, and optional login flows over your own database.

Udibo's managed identity service is in private beta. Join the waitlist. The self-hosted examples run locally without a hosted account.

Choose your path

Your application needsStart here
Udibo to handle sign-inUse Udibo's identity service — private-beta access required
Its own login and authorization serverRun the quickstart, then host authorization for your app
An API that accepts access tokensProtect an API
A React application with server-held tokensJuniper starter or React Router starter

Documentation index · API reference · Examples · Agent documentation

Install

Requires Deno 2 for the development workflow:

Shell
deno add jsr:@udibo/[email protected]

Import the part you use; there is no root barrel or default export:

TypeScript
import { BffClient, DirectClient } from "@udibo/oauth2/client";
import { HonoBff } from "@udibo/oauth2/hono/bff";
import { HonoResourceServer } from "@udibo/oauth2/hono/resource-server";

Version 0.1.0 is a pre-1.0 API. Minor releases may contain breaking changes; review the stability policy before upgrading.

How the pieces fit

For a browser app, use a backend-for-frontend (BFF). The browser holds an HttpOnly session cookie; the BFF exchanges authorization codes and keeps access and refresh tokens on the server. BffClient connects the browser to the BFF, and the React adapter uses that same client.

mermaid
sequenceDiagram
    participant Browser
    participant App as Your app / BFF
    participant Issuer as Udibo or your app's authorization server
    participant API as Your API
    Browser->>App: Start sign-in
    App-->>Browser: Redirect to authorization endpoint
    Browser->>Issuer: Sign in
    Issuer-->>Browser: Redirect back with code and state
    Browser->>App: Complete callback
    App->>Issuer: Exchange code with PKCE and client authentication
    Issuer-->>App: Tokens
    App-->>Browser: Session cookie
    Browser->>App: Request application data
    App->>API: Access token
    API-->>Browser: Application data, through the BFF

DirectClient is for a process that holds tokens: your backend, a CLI, a native app, or a public browser client. Supply a client secret only on the server. For a browser app with a backend, start with the BFF guide.

HonoResourceServer validates access tokens and enforces scopes on API routes. HonoAuthorizationServer issues tokens when your app hosts its own authorization server. The framework-independent core accepts standard Request and Response objects; Hono adapters add routing and middleware.

Examples

From a checkout of this repository:

Shell
deno ci
deno task serve:app-with-own-auth

Open http://localhost:8001/ and sign in as user / password. The quickstart explains what to try and which files to read. All demo credentials, in-memory stores, and local HTTP settings are for development.

ExampleDemonstrates
Hono with own authApp login, OAuth2 server, BFF, and protected API in one process
Hono with external authDelegated sign-in, token introspection, and a BFF proxy
Standalone APIBearer-token validation without a frontend
Juniper with own authServer-rendered React with application-owned login
Juniper with external authServer-rendered React with delegated sign-in

Package entrypoints

All paths below start with @udibo/oauth2. Each entrypoint has typed API docs and examples in the reference.

SubpathPurpose
/clientBffClient, DirectClient, token storage, discovery caching
/serverShared models, errors, scope types, and service contracts
/server/authorizationAuthorization server, grants, token/code services, signing keys
/server/resourceResource server, introspection and JWKS token readers
/server/public-suffixPublic Suffix List checks for optional wildcard redirect registration
/hono/authorization-serverHono authorization endpoints
/hono/resource-serverBearer authentication and scope middleware
/hono/bffBFF routes, server-held tokens, session and pending-login stores
/identityApp-owned signup, login, password reset, email verification, passwordless, and protection hooks
/identity/mfaTOTP, recovery codes, and MFA storage contract
/identity/externalSocial and external OIDC sign-in for your own login pages
/identity/migrationVerify imported password hashes and upgrade them at login
/hono/identityHono routes for IdentityService
/hono/logRequest logger and URL helper that redact every query value
/reactContext, hooks, authentication guards, and callback handling
/react/componentsOptional forms for login, signup, password reset, and MFA
/cryptoRandom tokens, hashing, encoding, authenticated encryption
/urlSafe return paths and login continuation
/cliLocal test identity provider and OIDC signing-key generation
/testingIn-memory fixtures and authorization-server test helpers
/testing/contractTests for app-owned service and storage implementations
/hono/bff/testingBFF session fixtures and session-store contract tests
/react/testingMock clients and providers for component tests

Runtime support

The library uses Web APIs. The complete suite runs on Deno. CI also builds an npm-format compatibility artifact and verifies 20 entrypoints with TypeScript and Node; this does not publish an npm package.

SurfaceDenoNodeBrowserBun
Clients and ReactTested, including SSRImport/type smoke-testedIntended for client code; no secretsNot verified
Server, identity, Hono, crypto, URL helpersTestedImport/type smoke-testedServer functionality belongs on the backendNot verified
/hono/bff/testing, /react/testingTestedImport/type smoke-testedReact test helpers onlyNot verified
/testing, /testing/contractTestedNot verifiedNot supportedNot verified
/cliDeno onlyNot supportedNot supportedNot supported

See stability for the support boundary.

Before deploying

Use the application deployment guide and deployment checklist. Keep PKCE, state, confidential-client authentication, and CSRF checks enabled. Replace development stores with persistent implementations where needed, and run the exported contract tests against those implementations.

Read known limitations for token-revocation, cookie-session, OIDC, and optional-protection behavior. Identity feature examples apply to apps hosting their own login; Udibo clients use the hosted sign-in flow.

For coding agents

Start with llms.txt for the task-to-guide map and integration rules. Use llms-full.txt when a single documentation download is useful. It is generated from the same guides developers read. Prefer the exported types and extension reference when implementing a custom store or callback.

Contributing and security

Run deno task check and deno task test:all before proposing changes. See CONTRIBUTING.md for development conventions, SECURITY.md for private vulnerability reports, and CHANGELOG.md for release history.