由 vee 出售

A Node.js client library for integrating FusionAuth authentication and identity APIs into your application. Deprecated in favor of the TypeScript client, but still published for existing users.
This block provides the official FusionAuth Node.js client library, enabling server-side Node.js applications to interact with a FusionAuth identity server via its REST API. It covers user management, authentication, JWT validation, and the full FusionAuth API surface. The typical buyer is a backend developer building authentication flows into a Node.js or Express application.
Deprecation notice: FusionAuth recommends migrating to
@fusionauth/typescript-client. This package remains functional but is no longer actively developed.
FusionAuthClient.js — Main API client; wraps every FusionAuth REST endpoint as a promise-returning method.RESTClient.js — Low-level HTTP builder used internally by FusionAuthClient; handles request construction, headers, and response parsing.ClientResponse.js — Response envelope returned by every API call; holds statusCode, successResponse, errorResponse, and exception.JWTManager.js — In-process JWT revocation cache with validity checking; independent of the REST client.npm install promise
No native modules, no build steps, no pod install. The library uses Node.js built-ins (http, https, url, querystring) for everything else.
Copy the source/ directory into your project, e.g. src/fusionauth/.
Reference the client from your code using a relative require/import:
// CommonJS
const { FusionAuthClient } = require('./fusionauth/FusionAuthClient');
// Or if you add an index.js barrel:
// const FusionAuthClient = require('./fusionauth/FusionAuthClient');
FUSIONAUTH_API_KEY=your-api-key
FUSIONAUTH_HOST=https://your-fusionauth-instance.example.com
FUSIONAUTH_TENANT_ID=your-tenant-uuid # optional, for multi-tenant setups
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This JavaScript library / package completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 4d93a6ecc5dcd00c…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
"allowJs": true"checkJs": falsetsconfig.json{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"esModuleInterop": true
}
}
const client = new FusionAuthClient(apiKey: string, host: string);
client.setTenantId(tenantId: string): FusionAuthClient;
client.actionUser(request: ActionRequest): Promise<ClientResponse<ActionResponse>>;
// + one method per FusionAuth API endpoint (login, register, retrieveUser, etc.)
FusionAuthClient is the primary entry point. Construct it once with your API key and host URL, optionally call setTenantId for multi-tenant deployments, then call any endpoint method. Every method returns a native Promise resolving to a ClientResponse.
class ClientResponse<T> {
statusCode: number | null;
successResponse: T | null;
errorResponse: Errors | null;
exception: Error | null;
wasSuccessful(): boolean;
}
Returned by every FusionAuthClient method. Call wasSuccessful() to check for a 2xx status with no exception, then read successResponse for the typed payload or errorResponse for FusionAuth validation errors. Inspect exception for network-level failures.
const JWTManager: {
revokedJWTs: Record<string, number>;
isValid(jwt: { sub: string; exp: number }): boolean;
revoke(userId: string, durationSeconds: number): void;
};
A singleton in-process revocation store. Call revoke when a user logs out or changes credentials. Call isValid in your middleware before accepting a decoded JWT. Note this is purely in-memory — it does not persist across restarts or share state between processes.
const rc = new RESTClient();
rc.authorization(key: string): RESTClient;
rc.uri(path: string): RESTClient;
rc.setJSONBody(body: object): RESTClient;
rc.post(): RESTClient;
rc.go(handler: Function): void;
Used internally by FusionAuthClient. You would only use RESTClient directly if you need to call a FusionAuth endpoint not yet wrapped by the client, or to add custom certificate/key material via rc.certificate and rc.key.
Call the FusionAuth Login API with application credentials and handle the response. Use this in an Express POST /login route.
const FusionAuthClient = require('./fusionauth/FusionAuthClient');
const client = new FusionAuthClient(
process.env.FUSIONAUTH_API_KEY,
process.env.FUSIONAUTH_HOST
);
async function loginUser(loginId: string, password: string, applicationId: string) {
const response = await client.login({
loginId,
password,
applicationId,
});
if (response.wasSuccessful()) {
const { token, user } = response.successResponse;
console.log('JWT:', token);
console.log('User id:', user.id);
return response.successResponse;
} else {
console.error('Login failed:', response.statusCode, response.errorResponse);
throw new Error('Authentication failed');
}
}
Create a user and register them to an application in a single call. Use during sign-up flows.
const FusionAuthClient = require('./fusionauth/FusionAuthClient');
const client = new FusionAuthClient(
process.env.FUSIONAUTH_API_KEY,
process.env.FUSIONAUTH_HOST
);
async function registerUser(email: string, password: string, applicationId: string) {
const response = await client.register(null, {
user: {
email,
password,
},
registration: {
applicationId,
},
});
if (response.wasSuccessful()) {
console.log('New user id:', response.successResponse.user.id);
return response.successResponse;
} else {
console.error('Registration error:', response.errorResponse);
throw new Error('Registration failed');
}
}
After a user logs out, revoke their JWTs in the local cache. In subsequent requests, validate a decoded JWT before allowing access.
const JWTManager = require('./fusionauth/JWTManager');
// On logout: revoke for the JWT's remaining lifetime (e.g. 3600 seconds)
function onUserLogout(userId: string, jwtDurationSeconds: number) {
JWTManager.revoke(userId, jwtDurationSeconds);
}
// In Express middleware: validate a decoded JWT payload
function jwtMiddleware(req: any, res: any, next: Function) {
const decodedJwt = req.decodedJwt; // assume upstream JWT decode already ran
if (!decodedJwt || !JWTManager.isValid(decodedJwt)) {
return res.status(401).json({ error: 'Token revoked or invalid' });
}
next();
}
Scope all API calls to a specific FusionAuth tenant by chaining setTenantId.
const FusionAuthClient = require('./fusionauth/FusionAuthClient');
const client = new FusionAuthClient(
process.env.FUSIONAUTH_API_KEY,
process.env.FUSIONAUTH_HOST
).setTenantId(process.env.FUSIONAUTH_TENANT_ID);
async function retrieveUser(userId: string) {
const response = await client.retrieveUser(userId);
if (response.wasSuccessful()) {
return response.successResponse.user;
}
throw new Error(`Failed to retrieve user: ${response.statusCode}`);
}
FusionAuthClient.js — Defines the FusionAuthClient constructor and its prototype, which contains one method per FusionAuth REST API endpoint. Each method uses RESTClient internally and returns a Promise<ClientResponse>.RESTClient.js — Builder-pattern HTTP client. Chainable methods configure the URL, headers, query parameters, and body; .go() executes the request and passes the parsed ClientResponse to a callback.ClientResponse.js — Simple response envelope constructor with statusCode, successResponse, errorResponse, exception fields, and a wasSuccessful() helper.JWTManager.js — Singleton object managing an in-memory map of revoked user JWTs keyed by user id. Exposes isValid, revoke, and a private _cleanUp method.FUSIONAUTH_HOST must include the scheme and no trailing slash — use https://auth.example.com, not auth.example.com/. A missing scheme causes http.request to throw immediately.setTenantId must be called before any API method — it mutates the client; if called after a concurrent request starts it may affect the wrong request. Create a new client instance per tenant in concurrent scenarios.JWTManager state is not shared across processes or restarts — in multi-process deployments (cluster mode, pm2, containers), revocations in one process are invisible to others. Use FusionAuth's server-side logout API (client.logout) as the authoritative revocation path.wasSuccessful() returns false for 401/403 even without a network error — check response.errorResponse for FusionAuth-level messages; do not assume a non-successful response means an exception was thrown.import { FusionAuthClient } from './FusionAuthClient.js' will fail. Use const FusionAuthClient = require('./FusionAuthClient.js') or add a wrapper barrel with export =.promise package must be installed — FusionAuthClient.js explicitly requires it (var Promise = require('promise')); relying on the global Promise is not enough as it is shadowed at module scope.I have dropped the FusionAuth Node.js client source files into src/fusionauth/.
The files are: FusionAuthClient.js, RESTClient.js, ClientResponse.js, JWTManager.js.
The upstream package is @fusionauth/node-client@1.51.0.
A USAGE.md file in that directory explains the full API, constructors, and working examples.
Please help me integrate this into my project step by step:
1. Read USAGE.md and the file excerpts to understand the real exports and signatures.
2. Add the `promise` npm dependency if it is not already installed.
3. Create a singleton FusionAuthClient instance using FUSIONAUTH_API_KEY and FUSIONAUTH_HOST env vars.
4. Wire up the following features in my existing Express app: [describe your login/register/logout routes here].
5. Add JWT revocation middleware using JWTManager.isValid() on protected routes.
6. Do not invent any methods — only use methods visible in FusionAuthClient.js and the USAGE.md examples.
The source is licensed under the Apache License 2.0. See source/ file headers for the full copyright notice.
Upstream package: @fusionauth/node-client by FusionAuth.
Upstream repository: https://github.com/FusionAuth/fusionauth-node-client.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
Automation, Utilities & Developer Tools
免费