npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cubicecho/better-auth-oidc-pairing

v1.2.1

Published

Pair a better-auth app with an OIDC provider from a setup URL: Dynamic Client Registration (RFC 7591/7592) on top of @better-auth/sso.

Readme

@cubicecho/better-auth-oidc-pairing

Pair a better-auth app with OpenID Connect providers by pasting one setup URL, instead of copying a client id, a secret and a redirect URI into its environment.

https://id.example.com/oidc#setup=<initial access token>&name=heautou

The app reads the issuer's discovery document, registers itself at its registration endpoint (RFC 7591) and keeps the client as a @better-auth/sso provider, so sign-in works at once, with no restart. Unpairing deletes the client at the provider (RFC 7592).

  • Several providers side by side: one set in the app's environment, kept fixed, and any number paired from setup URLs (five by default).
  • Providers on a LAN work. better-auth trusts only public hosts by default, and the plugin trusts each provider's origins for as long as it is paired.
  • A sign-in can end in a one-time token the app spends over its own API, so the session never rides in a URL.

Every paired provider can sign in as any address it vouches for, because accounts link by address. Say so on the page where providers are added, and let only the right people pair.

Install

npm install @cubicecho/better-auth-oidc-pairing better-auth @better-auth/sso

better-auth and @better-auth/sso are peer dependencies, >=1.7.28 <1.8.0. Node 22 or later, ESM only.

Quick start

Save this as server.mjs and run node server.mjs (Node 22.13 or later, for node:sqlite).

import { createServer } from 'node:http';
import { DatabaseSync } from 'node:sqlite';
import { oidcPairingPlugins } from '@cubicecho/better-auth-oidc-pairing';
import { betterAuth } from 'better-auth';
import { getMigrations } from 'better-auth/db/migration';
import { toNodeHandler } from 'better-auth/node';
import { bearer } from 'better-auth/plugins';

const database = new DatabaseSync('app.db');

const auth = betterAuth({
  baseURL: 'http://localhost:3000',
  secret: 'replace-me-with-32-random-characters-or-more',
  database,
  plugins: [
    bearer(),
    ...oidcPairingPlugins({
      clientName: 'my-app',
      // Who may pair, unpair and see issuer URLs: the first account, or anyone while there are none.
      canPair: ({ userId }) => {
        const owner = database.prepare('SELECT id FROM user ORDER BY createdAt LIMIT 1').get();
        return owner === undefined || owner.id === userId;
      },
      // The provider the operator set in the environment, or null for none.
      pinned: null,
      // The page that spends the one-time token, and the login page, which reads ?error=.
      signedInURL: '/auth/sso',
      errorURL: '/login',
    }),
  ],
});

const { runMigrations } = await getMigrations(auth.options);
await runMigrations();

const page = (script) => `<!doctype html><body><script type="module">${script}</script>`;

// One link per provider: a full-page navigation, not a fetch.
const login = page(`
  const { providers } = await (await fetch('/api/auth/oidc-pairing/providers')).json();
  for (const { providerId, name } of providers) {
    const link = document.createElement('a');
    link.href = '/api/auth/oidc-pairing/sign-in/' + providerId;
    link.textContent = 'Sign in with ' + name;
    document.body.append(link);
  }`);

// Spends the token once, for the bearer session.
const signedIn = page(`
  const token = new URLSearchParams(location.search).get('token');
  const response = await fetch('/api/auth/oidc-pairing/verify', {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ token }),
  });
  const session = await response.json();
  if (response.ok) localStorage.setItem('session', session.token);
  document.body.append(response.ok ? 'Signed in as ' + session.userId : session.message);`);

const handleAuth = toNodeHandler(auth);
createServer((req, res) => {
  if (req.url.startsWith('/api/auth/')) return handleAuth(req, res);
  res.setHeader('content-type', 'text/html');
  res.end(req.url.startsWith('/auth/sso') ? signedIn : login);
}).listen(3000);

Then pair a provider with the setup URL it gave you, and sign in at http://localhost:3000/login:

curl http://localhost:3000/api/auth/oidc-pairing/pair \
  -H 'content-type: application/json' \
  -d '{"setupUrl":"https://id.example.com/oidc#setup=...&name=heautou"}'

Documentation

License

MIT