Registry / auth-security / node-weixin-auth

node-weixin-auth

JSON →
library0.6.3jsnpmunverified

WeChat server authentication module for node-weixin-api and node-weixin-express. Version 0.6.3 provides token acquisition, automatic token refresh with configurable GAP, server IP retrieval, and message signature verification. It is part of the node-weixin ecosystem and requires node-weixin-settings for configuration persistence. Compared to other WeChat SDKs, it offers manual and automatic tokenization with a time gap to reduce expiration failures. The package has a moderate release cadence and is primarily used in Chinese development communities.

npm install node-weixin-auth
INSTALL
IMPORT
SIG · NODE-WEIXIN-AUTH
N
node-weixin-auth
auth-securityjavascriptv0.6.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

nodeWeixinAuth
import nodeWeixinAuth from 'node-weixin-auth'
const nodeWeixinAuth = require('node-weixin-auth')
The package uses CommonJS and has no default export; require is standard. ES import works if module resolution supports default fallback.
tokenize
nodeWeixinAuth.tokenize(settings, app, callback)
Manually fetches an access token from WeChat API.
determine
nodeWeixinAuth.determine(settings, app, function) { ... })
nodeWeixinAuth.determine(settings, app, callback)
Automatically tokenizes API requests, refreshing token if needed.

Initializes WeChat auth with app credentials, manually fetches a token, and sets up automatic token refresh.

const nodeWeixinAuth = require('node-weixin-auth'); const settings = require('node-weixin-settings'); const app = { id: process.env.WECHAT_APP_ID || '', secret: process.env.WECHAT_APP_SECRET || '', token: process.env.WECHAT_TOKEN || '' }; // Optional: set time gap for token refresh nodeWeixinAuth.TIME_GAP = 60; // Manually get access token nodeWeixinAuth.tokenize(settings, app, (error, json) => { if (!error) { console.log('Access Token:', json.access_token); } }); // Automatically handle token for subsequent requests nodeWeixinAuth.determine(settings, app, () => { console.log('Token is ready. You can now make API calls.'); });
Debug
Known issues
breakingThe callback signature for determine may differ from tokenize; ensure you pass a function with no arguments.
fix
Use determine(settings, app, function() { ... }) without parameters in the callback.
affects: >=0.0.0
gotchaThe TIME_GAP property must be set before calling determine; otherwise default 500 seconds is used.
fix
Set nodeWeixinAuth.TIME_GAP = <desired seconds> before calling determine.
affects: >=0.0.0
gotchaThe ack method expects a data object from extract; ensure you call nodeWeixinAuth.extract(req.query) on GET request query parameters.
fix
Parse query string with extract before passing to ack.
affects: >=0.0.0
gotchaIf settings are not properly configured, tokenize may throw an error without clear message; validate app object has non-empty id and secret.
fix
Check that app.id, app.secret, and app.token are set to valid WeChat credentials.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot read property 'access_token' of undefined
tokenize callback called with error but code accesses json.access_token without check.
fix
Check if (!error && json) before using json.access_token.
nodeWeixinAuth is not a function
Importing incorrectly, e.g., import nodeWeixinAuth from 'node-weixin-auth' when require is expected or module has no default export.
fix
Use const nodeWeixinAuth = require('node-weixin-auth');.
TypeError: settings.get is not a function
The settings object must be a node-weixin-settings instance, not a plain object.
fix
Create settings with require('node-weixin-settings') and configure it.
Upgrade
Version history
0.6.3latest on npm
Audit
Dependencies
node-weixin-settingsrequiredRequired for storing and retrieving WeChat app settings (id, secret, token).
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
node-weixin-auth — npm install node-weixin-auth · libregistry