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

@55387.ai/uniauth-server

v1.2.4

Published

UniAuth Server SDK - Token verification for Node.js backends

Downloads

350

Readme

@55387.ai/uniauth-server

UniAuth Backend SDK — Token verification & middleware for Node.js servers.

UniAuth 后端 SDK — Node.js 服务端令牌验证和中间件。

Version / 版本: 1.2.2

Install / 安装

npm install @55387.ai/uniauth-server
# or / 或
pnpm add @55387.ai/uniauth-server

Quick Start / 快速开始

import { UniAuthServer } from '@55387.ai/uniauth-server';

const auth = new UniAuthServer({
  baseUrl: 'https://sso.55387.xyz',
  clientId: process.env.UNIAUTH_CLIENT_ID!,
  clientSecret: process.env.UNIAUTH_CLIENT_SECRET!,
});

// Verify token / 验证令牌
const payload = await auth.verifyToken(accessToken);
console.log('User ID:', payload.sub);

Middleware / 中间件

Express

import express from 'express';
const app = express();

app.use('/api/*', auth.middleware());

app.get('/api/profile', (req, res) => {
  res.json({ user: req.user, payload: req.authPayload });
});

Hono

import { Hono } from 'hono';
const app = new Hono();

app.use('/api/*', auth.honoMiddleware());

app.get('/api/profile', (c) => {
  return c.json({ user: c.get('user') });
});

SSO Backend Proxy / SSO 后端代理

When your app is a Confidential Client, token exchange must happen on the server.

当应用配置为 机密客户端 时,Token 交换必须在服务端完成。

User → Frontend → /api/auth/login → Backend → redirect to UniAuth SSO
                                                      ↓
User ← Frontend ← redirect ← Backend (set cookie) ← SSO callback
                                      ↑
                         Backend exchanges code with client_secret

See full implementation: AI Integration Guide

完整实现见: 集成指南

Token Introspection / 令牌内省

RFC 7662 compliant token introspection:

const result = await auth.introspectToken(accessToken);

if (result.active) {
  console.log('User:', result.sub);
  console.log('Scope:', result.scope);
}

API Reference / API 参考

Config / 配置

interface UniAuthServerConfig {
  baseUrl: string;        // UniAuth server URL
  clientId: string;       // OAuth2 client ID
  clientSecret: string;   // OAuth2 client secret
  jwtPublicKey?: string;  // JWT public key (local verification)
}

Methods / 方法

| Method | Description / 说明 | |--------|-----------| | verifyToken(token) | Verify access token / 验证访问令牌 | | introspectToken(token) | RFC 7662 introspection / 令牌内省 | | isTokenActive(token) | Check if token is active / 检查令牌状态 | | getUser(userId) | Get user info / 获取用户信息 | | middleware() | Express middleware / Express 中间件 | | honoMiddleware() | Hono middleware / Hono 中间件 | | clearCache() | Clear token cache / 清除令牌缓存 |

Token Verification Flow / 令牌验证流程

verifyToken(token)
  │
  ├─ 1. POST /api/v1/auth/verify (App Key + Secret)
  │     ↓ success → return payload
  │     ↓ 404 or network error
  │
  ├─ 2. POST /api/v1/oauth2/introspect (Basic Auth, RFC 7662)
  │     ↓ active:true → return payload
  │     ↓ fail
  │
  └─ 3. Local JWT verification (if jwtPublicKey configured)

Types / 类型

interface TokenPayload {
  sub: string;              // User ID
  iss?: string;             // Issuer
  aud?: string | string[];  // Audience
  exp: number;              // Expiration
  iat: number;              // Issued at
  scope?: string;           // Scopes
  phone?: string;           // Phone number
  email?: string;           // Email
}

Error Handling / 错误处理

import { ServerAuthError, ServerErrorCode } from '@55387.ai/uniauth-server';

try {
  await auth.verifyToken(token);
} catch (error) {
  if (error instanceof ServerAuthError) {
    switch (error.code) {
      case ServerErrorCode.INVALID_TOKEN:  // Invalid / 令牌无效
      case ServerErrorCode.TOKEN_EXPIRED:  // Expired / 令牌过期
    }
  }
}

🤖 AI Agent Prompts / AI 智能体提示词

This package includes an AI-ready integration prompt. Copy it into your AI coding assistant (Claude, Cursor, Copilot, etc.) to generate a complete backend protection setup automatically.

本包附带 AI 集成提示词。将其复制到 AI 编程助手中,即可自动生成完整的后端保护代码。

# After install, find the prompt at:
# 安装后,提示词文件位于:
cat node_modules/@55387.ai/uniauth-server/ai-prompts/backend-protection.md

[!TIP] Replace placeholders like YOUR_UNIAUTH_URL and YOUR_CLIENT_SECRET before pasting into your AI assistant. 粘贴到 AI 助手前,请替换 YOUR_UNIAUTH_URLYOUR_CLIENT_SECRET 等占位符。

See all prompts: docs/ai-prompts/

License

MIT