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

@nya-account/node-sdk

v2.0.2

Published

Official Node.js SDK for Nya Account SSO — OAuth 2.1 / OIDC client with PKCE, JWT verification, and Express middleware

Readme

@nya-account/node-sdk

Official Node.js SDK for Nya Account SSO system.

Provides a complete OAuth 2.1 / OIDC client with PKCE, JWT verification, and Express middleware.

Installation

npm install @nya-account/node-sdk
# or
pnpm add @nya-account/node-sdk
# or
yarn add @nya-account/node-sdk

Quick Start

import { NyaAccountClient } from '@nya-account/node-sdk'

const client = new NyaAccountClient({
    // See https://account.lolinya.net/docs/developer/service-endpoints#integration-endpoints
    issuer: 'https://account-api.edge.lolinya.net',
    clientId: 'my-app',
    clientSecret: 'my-secret'
})

// Create authorization URL (with PKCE)
const { url, codeVerifier, state } = await client.createAuthorizationUrl({
    redirectUri: 'https://myapp.com/callback',
    scope: 'openid profile email'
})

// Exchange code for tokens
const tokens = await client.exchangeCode({
    code: callbackCode,
    redirectUri: 'https://myapp.com/callback',
    codeVerifier
})

// Get user info
const userInfo = await client.getUserInfo(tokens.accessToken)

// Revoke refresh token on logout
await client.revokeToken(tokens.refreshToken, { tokenTypeHint: 'refresh_token' })

// Build RP-initiated logout URL
const logoutUrl = await client.createEndSessionUrl({
    idTokenHint: tokens.idToken,
    postLogoutRedirectUri: 'https://myapp.com/logout/callback',
    state: 'logout-csrf-state'
})

Express Middleware

import express from 'express'
import { NyaAccountClient } from '@nya-account/node-sdk'
import { getAuth } from '@nya-account/node-sdk/express'

const app = express()
const client = new NyaAccountClient({
    issuer: 'https://account-api.edge.lolinya.net',
    clientId: 'my-app',
    clientSecret: 'my-secret'
})

// Protect all /api routes
app.use('/api', client.authenticate())

app.get('/api/me', (req, res) => {
    const auth = getAuth(req)
    res.json({ userId: auth?.sub, scopes: auth?.scope })
})

// Require specific scopes
app.get(
    '/api/profile',
    client.authenticate(),
    client.requireScopes('profile'),
    (req, res) => {
        const auth = getAuth(req)
        res.json({ name: auth?.sub })
    }
)

// Use introspection for sensitive operations
app.post('/api/sensitive', client.authenticate({ strategy: 'introspection' }), handler)

Configuration

| Option | Type | Default | Description | | ------------------- | ---------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | issuer | string | 'https://account-api.edge.lolinya.net' | SSO service URL (Issuer URL). See Service Endpoints for available endpoints. | | clientId | string | required | OAuth client ID | | clientSecret | string | required | OAuth client secret | | timeout | number | 10000 | HTTP request timeout in milliseconds | | discoveryCacheTtl | number | 3600000 | Discovery document cache TTL in milliseconds (default: 1 hour) | | endpoints | EndpointConfig | — | Explicitly specify endpoint URLs (auto-discovered via OIDC Discovery if omitted) |

API Reference

NyaAccountClient

Authorization

  • createAuthorizationUrl(options) — Create an OAuth authorization URL with PKCE
  • pushAuthorizationRequest(options) — Push authorization request to PAR endpoint (RFC 9126)
  • createAuthorizationUrlWithPar(options) — Create authorization URL using PAR request_uri

Token Operations

  • exchangeCode(options) — Exchange an authorization code for tokens
  • refreshToken(refreshToken) — Refresh an Access Token
  • revokeToken(token, options?) — Revoke a token (RFC 7009)
  • introspectToken(token, options?) — Token introspection (RFC 7662)

User Info

  • getUserInfo(accessToken) — Get user info via OIDC UserInfo endpoint

JWT Verification

  • verifyAccessToken(token, options?) — Locally verify a JWT Access Token (RFC 9068)
  • verifyIdToken(token, options?) — Locally verify an OIDC ID Token

Express Middleware

  • authenticate(options?) — Middleware to verify Bearer Token (local or introspection strategy)
  • requireScopes(...scopes) — Middleware to validate token scopes

Cache

  • discover() — Fetch OIDC Discovery document (cached with TTL)
  • clearCache() — Clear Discovery and JWT verifier cache

OIDC Logout

  • createEndSessionUrl(options?) — Create OIDC RP-initiated logout URL (end_session_endpoint)

Express Helpers

Available from @nya-account/node-sdk/express:

  • getAuth(req) — Retrieve the verified Access Token payload from a request
  • extractBearerToken(req) — Extract Bearer token from the Authorization header
  • sendOAuthError(res, statusCode, error, errorDescription) — Send an OAuth-standard error response

PKCE Utilities

  • generatePkce() — Generate a code_verifier and code_challenge pair
  • generateCodeVerifier() — Generate a PKCE code_verifier
  • generateCodeChallenge(codeVerifier) — Generate an S256 code_challenge

Error Handling

The SDK provides typed error classes:

import {
    NyaAccountError, // Base error class
    OAuthError, // OAuth protocol errors from the server
    TokenVerificationError, // JWT verification failures
    DiscoveryError // OIDC Discovery failures
} from '@nya-account/node-sdk'

try {
    await client.verifyAccessToken(token)
} catch (error) {
    if (error instanceof TokenVerificationError) {
        console.log(error.code) // 'token_verification_failed'
        console.log(error.description) // Human-readable description
    }
}

Requirements

  • Node.js >= 20.0.0
  • Express 4.x or 5.x (optional, for middleware features)

License

MIT