{"id":18618,"library":"node-weixin-auth","title":"node-weixin-auth","description":"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.","status":"active","version":"0.6.3","language":"javascript","source_language":"en","source_url":"https://github.com/node-weixin/node-weixin-auth","tags":["javascript"],"install":[{"cmd":"npm install node-weixin-auth","lang":"bash","label":"npm"},{"cmd":"yarn add node-weixin-auth","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-weixin-auth","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for storing and retrieving WeChat app settings (id, secret, token).","package":"node-weixin-settings","optional":false}],"imports":[{"note":"The package uses CommonJS and has no default export; require is standard. ES import works if module resolution supports default fallback.","wrong":"const nodeWeixinAuth = require('node-weixin-auth')","symbol":"nodeWeixinAuth","correct":"import nodeWeixinAuth from 'node-weixin-auth'"},{"note":"Manually fetches an access token from WeChat API.","symbol":"tokenize","correct":"nodeWeixinAuth.tokenize(settings, app, callback)"},{"note":"Automatically tokenizes API requests, refreshing token if needed.","wrong":"nodeWeixinAuth.determine(settings, app, callback)","symbol":"determine","correct":"nodeWeixinAuth.determine(settings, app, function) { ... })"}],"quickstart":{"code":"const nodeWeixinAuth = require('node-weixin-auth');\nconst settings = require('node-weixin-settings');\n\nconst app = {\n  id: process.env.WECHAT_APP_ID || '',\n  secret: process.env.WECHAT_APP_SECRET || '',\n  token: process.env.WECHAT_TOKEN || ''\n};\n\n// Optional: set time gap for token refresh\nnodeWeixinAuth.TIME_GAP = 60;\n\n// Manually get access token\nnodeWeixinAuth.tokenize(settings, app, (error, json) => {\n  if (!error) {\n    console.log('Access Token:', json.access_token);\n  }\n});\n\n// Automatically handle token for subsequent requests\nnodeWeixinAuth.determine(settings, app, () => {\n  console.log('Token is ready. You can now make API calls.');\n});","lang":"typescript","description":"Initializes WeChat auth with app credentials, manually fetches a token, and sets up automatic token refresh."},"warnings":[{"fix":"Use determine(settings, app, function() { ... }) without parameters in the callback.","message":"The callback signature for determine may differ from tokenize; ensure you pass a function with no arguments.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Set nodeWeixinAuth.TIME_GAP = <desired seconds> before calling determine.","message":"The TIME_GAP property must be set before calling determine; otherwise default 500 seconds is used.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Parse query string with extract before passing to ack.","message":"The ack method expects a data object from extract; ensure you call nodeWeixinAuth.extract(req.query) on GET request query parameters.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check that app.id, app.secret, and app.token are set to valid WeChat credentials.","message":"If settings are not properly configured, tokenize may throw an error without clear message; validate app object has non-empty id and secret.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Check if (!error && json) before using json.access_token.","cause":"tokenize callback called with error but code accesses json.access_token without check.","error":"Cannot read property 'access_token' of undefined"},{"fix":"Use const nodeWeixinAuth = require('node-weixin-auth');.","cause":"Importing incorrectly, e.g., import nodeWeixinAuth from 'node-weixin-auth' when require is expected or module has no default export.","error":"nodeWeixinAuth is not a function"},{"fix":"Create settings with require('node-weixin-settings') and configure it.","cause":"The settings object must be a node-weixin-settings instance, not a plain object.","error":"TypeError: settings.get is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}