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

@golojan/auth

v2.0.9

Published

Enterprise-grade SSO-enabled authentication SDK for OAuth2/OpenID authorization code with PKCE.

Readme

@golojan/auth

Enterprise SSO authentication SDK for OAuth2/OpenID Connect using Authorization Code + PKCE.

Install

// npm
npm i @golojan/auth

Quick Start (Browser/Node)

import { createAuthClient } from '@golojan/auth';

const auth = createAuthClient({
  clientId: '<client-id>',
  clientSecret: '<client-secret>',
  redirectUri: 'https://app.example.com/api/callback',
  scope: 'openid profile email',
});

Core Flow

// 1) Redirect user to SSO login
await auth.login();

// 2) On callback URL, exchange code
await auth.handleCallback(window.location.href);

// 3) Call userinfo
const me = await auth.userinfo();

Next.js App Router (Recommended)

Use the reusable helpers from @golojan/auth/next.

1) Runtime auth client

// app/lib/auth.ts
import { createAuthClient } from '@golojan/auth';

const CLIENT_ID = process.env.NEXT_PUBLIC_OPENID_CLIENT_ID!;
const CLIENT_SECRET = process.env.OPENID_CLIENT_SECRET; // optional
const DEFAULT_ORIGIN = process.env.NEXT_PUBLIC_APP_ORIGIN ?? 'http://localhost:3000';

export const createRuntimeAuthClient = (origin = DEFAULT_ORIGIN) =>
  createAuthClient({
    clientId: CLIENT_ID,
    clientSecret: CLIENT_SECRET,
    redirectUri: `${origin}/api/callback`,
    scope: 'openid profile email',
  });

2) Protect routes with proxy.ts

// proxy.ts
import { createAuthProxy, defaultAuthProxyMatcher } from '@golojan/auth/next';

const PUBLIC_ROUTES = ['/', '/api/callback'] as const;

export default createAuthProxy({
  callbackPath: '/api/callback',
  publicRoutes: [...PUBLIC_ROUTES],
});

export const config = {
  matcher: defaultAuthProxyMatcher,
};

3) Handle callback and code exchange

// app/api/callback/route.ts
import { createAuthCallbackHandler } from '@golojan/auth/next';
import { createRuntimeAuthClient } from '@/app/lib/auth';

export const GET = createAuthCallbackHandler({
  createAuthClient: createRuntimeAuthClient,
  callbackPath: '/api/callback',
  // optional: sync access token to client memory store
  accessTokenSyncCookieName: 'golojan_console_access_token_sync',
});

Important Parameters

  • redirectUri: OAuth client config value (your app callback URL, e.g. https://app.example.com/api/callback).
  • redirectTo: SSO URL query param pointing to your callback URL.
  • returnTo: SSO URL query param for the final in-app destination after callback/code exchange.
  • state: signed/encoded context, includes returnTo.

createAuthProxy sets redirectTo, returnTo, and state automatically. It also writes a short-lived returnTo cookie so callback redirect can recover even if upstream state is rewritten. For mixed deployments, login URL generation includes legacy aliases (redirectUri, redirect_uri, return_to) in addition to canonical keys.

API Surface (Core SDK)

  • loadDiscovery(): Promise<DiscoveryDoc>
  • createLoginUrl(options?): Promise<string>
  • login(options?): Promise<string>
  • handleCallback(url): Promise<TokenSet>
  • exchangeAuthorizationCode(args): Promise<TokenSet>
  • exchangeAuthorizationCodeDetailed(args): Promise<{ tokenSet, setCookieHeaders }>
  • getTokens(): TokenSet | null
  • setTokens(tokens): void
  • clearTokens(): void
  • clearPendingAuth(): void
  • clearClientState(): void
  • userinfo(accessToken?): Promise<T>
  • refresh(request?): Promise<TokenSet>
  • logoutUrl(options?): Promise<string>
  • logout(options?): Promise<string>

API Surface (@golojan/auth/next)

  • createAuthProxy(options?): (request: NextRequest) => NextResponse
  • authProxy (default proxy instance)
  • createAuthCallbackHandler(options): (request: Request) => Promise<NextResponse>
  • defaultAuthProxyMatcher

Platform Defaults

  • AUTH_API_BASE_URL: https://api.golojan.com/v1
  • AUTH_SWAGGER_JSON_URL: https://api.golojan.com/v1/auth/docs-json
  • AUTH_DEFAULT_ISSUER: https://api.golojan.com/v1/auth
  • AUTH_DEFAULT_AUTHORIZATION_ENDPOINT: https://accounts.golojan.com/auth/login

Storage Defaults

  • Pending auth: SessionPendingAuthStorage (default, TTL-aware)
  • Tokens: MemoryTokenStorage (default)
  • Optional persistence: createLocalTokenStorage()

Security Notes

  • Uses PKCE (S256) + state validation.
  • Uses top-level redirects for multi-domain SSO compatibility.
  • Callback enforces same-origin returnTo normalization.
  • Do not store secrets/tokens in logs or analytics.