passport-wechat-mp
v1.0.1
Published
passport strategy for wechat mini program
Downloads
4
Maintainers
Readme
passport-wechat-mp
Wechat Mini Program authentication strategy for Passport.
Install
$ npm install passport-wechat-mp
# yarn add passport-wechat-mp
Usage
Configure Strategy
const WechatMPStrategy = require('passport-wechat-mp').Strategy;
passport.use(
'wechat-mp',
new WechatMPStrategy(
{
appId: app.get('wechatMPAppId'),
appSecret: app.get('wechatMPSecret')
},
async (req, profile, done) => {
// profile
// {
// openid,
// unionid,
// session_key
// }
User.findOrCreate({ exampleId: profile.openid }, (err, user) => {
return cb(err, user);
});
}
)
)
Strategy constructor options:
appId
: String, required, wechat miniprogram appid.appSecret
: String, required, wechat miniprogram app secret.name
: String, optional, strategy name. Default aswechat-mp
.authorizationURL
: String, optional, url to fetch wechat session key by code, check wechat doc for more details. Default ashttps://api.weixin.qq.com/sns/jscode2session
.
Authenticate Requests
const passport = require('passport');
app.get('/mp/login', passport.authenticate('wechat-mp', {
successRedirect: '/api/memberships/profile/me',
failureRedirect: '/error'
}));
Test
$ npm test
# yarn test
TODO
- [ ] Strategy unit test