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

@yan06/openai-oauth-web

v2.0.2

Published

Browser credential storage and web utilities for openai-oauth.

Readme

@yan06/openai-oauth-web

Docs | GitHub | npm

Framework-neutral browser sign-in primitives for OpenAI OAuth.

npm i @yan06/openai-oauth-web

Most React apps should use @yan06/openai-oauth-react, which depends on this package and re-exports the common browser helpers.

import { openaiAuthHeaders } from "@yan06/openai-oauth-web";

await fetch("/api/chat", {
	method: "POST",
	headers: await openaiAuthHeaders(),
	body: "Hello!",
});

Package Notes

@yan06/openai-oauth-web is the lower-level web package. Use it when you need browser primitives without React.

Model requests cannot be made directly from a browser due to CORS. This also applies for Desktop apps inside a WebView or browser renderer such as Electron or Tauri. You can use this package for sign-in and session storage, but run model requests through native desktop networking.

Hosted Sign-in

Hosted browser sign-in uses the open-source Sign in with ChatGPT extension for Chrome or Firefox to complete OpenAI's local OAuth callback. The extension shows the destination app for confirmation and then returns the callback directly to it.

startLogin() uses this extension flow by default. When installation is needed, it returns the correct Chrome Web Store or Firefox Add-ons URL for your interface to display:

import { startLogin } from "@yan06/openai-oauth-web";

const result = await startLogin();

if (result.status === "needs-extension") {
	installLink.href = result.installUrl;
	installScreen.hidden = false;
}

After installation, call startLogin() again when the user returns to your app or presses Sign in again. It will start OAuth once the extension is available.

The extension redirects only http://localhost:1455/auth/callback. After the user confirms the destination, call completeLogin() on the returned app URL to exchange the code and save the browser session.

startLogin() returns { status: "started" } when OAuth begins or { status: "needs-extension", installUrl } when your interface should show installation UI. Provide an explicit redirectUri only when your environment handles its own registered callback without the extension.

Browser Session

import { createSessionStore, getSession, openaiAuthHeaders } from "@yan06/openai-oauth-web";

const sessionStore = createSessionStore();
const session = await getSession({ sessionStore });
const headers = await openaiAuthHeaders({ sessionStore });

getSession() reads the browser session store and refreshes with the stored refresh token when needed.

openaiAuthHeaders() returns a plain object of request headers for your own app route:

const headers = await openaiAuthHeaders({
	headers: { "content-type": "application/json" },
});

Because it returns a plain object, the result can be passed directly to fetch, AI SDK hooks, and other code that spreads header objects.

It includes:

  • Authorization: Bearer <access token>
  • chatgpt-account-id: <account id>

Server Credentials

Use @yan06/openai-oauth-web/server in the app route that receives those headers:

import { createOpenAIOAuth } from "@yan06/openai-oauth-ai-sdk";
import { openaiCredentials } from "@yan06/openai-oauth-web/server";
import { generateText } from "ai";

export async function POST(request: Request) {
	const openai = createOpenAIOAuth(openaiCredentials(request));

	const result = await generateText({
		model: openai("gpt-5.4-mini"),
		prompt: await request.text(),
	});

	return new Response(result.text);
}

openaiCredentials(request) reads the request headers and returns an OpenAIOAuth credential source for client adapters.

Session Store

The default store persists the session in IndexedDB and encrypts each payload with a non-extractable WebCrypto AES-GCM key.

Apps can provide their own store:

type SessionStore = {
	get(): Promise<OpenAIOAuthSession | null>;
	set(session: OpenAIOAuthSession): Promise<void>;
	clear(): Promise<void>;
};

Direct Token Exchange

import { exchangeCode, refreshSession } from "@yan06/openai-oauth-web";

const session = await exchangeCode({
	code,
	codeVerifier,
	redirectUri,
});

const refreshed = await refreshSession({
	refreshToken: session.refreshToken,
});

Login Helpers

import { completeLogin, logout, startLogin } from "@yan06/openai-oauth-web";

await startLogin();
await completeLogin();
await logout();

completeLogin() returns the signed-in session when the current URL contains an OAuth callback, and null when there is no callback to complete.

Useful browser options:

type BrowserSessionOptions = {
	sessionStore?: SessionStore;
	clientId?: string;
	issuer?: string;
	tokenUrl?: string;
	fetch?: typeof fetch;
	refresh?: boolean;
	now?: () => Date;
};

Useful server options:

type WebServerOpenAIOAuthOptions = {
	baseURL?: string;
	fetch?: typeof fetch;
	headers?: Record<string, string>;
	instructions?: string;
	openAIBaseURL?: string;
};

More

Learn more in the openai-oauth README.