Express-weapp-auth
Express middleware to decrypt wechat userInfo data for weapp login scenario.
Installation
# via Github
npm install xixilive/express-weapp-auth --save
# via npm
npm install express-weapp-auth --save
Usage
// basic example const app = app // advance exampleapp
Middleware
// all arguments // without optional arguments // without options argument // without paramsResolver argument
Arguments
-
appId
: required, weapp app ID -
appSecret
: required, weapp app secret -
paramsResolver
: optional, afunction(req){}
to resolve auth-params for request object -
options
: optional,{dataKey: 'the key assign to req object to store decrypted data'}
ParamsResolver(req)
It will use a built-in default resolver to resolve params for request if there has no function passed to middleware function. and the default function resolves params in a certain priority:
-
req.body
with the highest priority -
req.query
with middle priority -
req.params
with the lowest priority
And it expects the resolver function to return an object value with following structure:
code: 'login code' rawData: 'rawData' signature: 'signature for rawData' encryptedData: 'encrypted userInfo' iv: 'cipher/decipher vector'
For more details about this, please visit 微信小程序 API