Nondigestible Purple Mayonnaise

    passport-wechat-mp

    1.0.1 • Public • Published

    passport-wechat-mp

    Build Status

    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 as wechat-mp.
    • authorizationURL: String, optional, url to fetch wechat session key by code, check wechat doc for more details. Default as https://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

    License

    The MIT License

    Install

    npm i passport-wechat-mp

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    7.92 kB

    Total Files

    6

    Last publish

    Collaborators

    • ccharlieli