egg-passport-weixin-pc

weixin passport plugin for egg

Usage no npm install needed!

<script type="module">
  import eggPassportWeixinPc from 'https://cdn.skypack.dev/egg-passport-weixin-pc';
</script>

README

egg-passport-weixin

NPM version build status Test coverage David deps Known Vulnerabilities npm download

微信网站应用第三方登录

  • 支持登录成功跳转回之前页面

依赖说明

依赖的 egg 版本

egg-passport-weixin 版本 egg 1.x
1.x 😁
0.x

依赖的插件

开启插件

// config/plugin.js
exports.passportWeixin = {
  enable: true,
  package: 'egg-passport-weixin',
};

使用方式

开启插件

// config/plugin.js
module.exports.passport = {
  enable: true,
  package: 'egg-passport'
}

module.exports.passportAlipay = {
  enable: true,
  package: 'egg-passport-alipay'
}

配置

// config/config.xx.js
exports.passportAlipay = {
  key: '',  // appid
  secret: '', // secret
  callbackURL: '/passport/weixin/callback', // callbackurl
  scope: 'snsapi_login'
}

挂载路由

// app/router.js
router.get('/passport/weixin', {})
router.get('/passport/weixin/callback', app.passport.authenticate('weixin', { failureRedirect: '/member/login.html', successRedirect: '/' })

用户信息处理

// app.js
app.passport.verify(async (ctx, user) => {
  // 调用第三方登录接口 或 保存到session
  return user
})

支持登录成功跳转回之前页面

在跳转第三方登录入口链接上添加?done=url即可

详细配置

请到 config/config.default.js 查看详细配置项说明。

单元测试

提问交流

请到 egg issues 异步交流。

License

MIT