npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

passport-wechat-work-whale

v1.0.0

Published

[Passport](http://passportjs.org/) strategy for authenticating with [Wechat Work Accounts](https://qy.weixin.qq.com/) using the OAuth 2.0 API.

Downloads

4

Readme

passport-wechat-work

Passport strategy for authenticating with Wechat Work Accounts using the OAuth 2.0 API.

Passport的企业微信OAuth2.0, 二维码扫码登录,用户验证模块, 支持Express,Strongloop|Loopback.

本程序基于passport-wechat-enterprise源码改写.

企业微信开发文档

微信企业号,转至 passport-wechat-enterprise

微信公众号,转至 passport-wechat-public

Install

$ npm install passport-wechat-work

Usage

Configure Strategy

  • 在Passport注册WechatWorkStrategy, Passport.use()的第一个参数是name,可以忽略使用默认的名字’wechat-work'。WechatWorkStrategy的构造函数的参数是options,verify 以及getAccessToken和saveAccessToken。

    options的corpId,corpSecret, agentId和callbackURL是必需的,其他为可选。verify函数是验证或创建用户传给done函数, getAccessToken和saveAccessToken用已获得AccessToken和保存新的AccessToken,当getAccessToken返回的AccessToken无效时,会通过调用微信的/gettoken接口获取新的AccessToken,并用saveAccessToken进行保存。getAccessToken and saveAccessToken 都是必需的。 options的href 可以用来传递微信企业二维码链接的css美化,可参考v.qq.com的微信登录链接

passport.use("wechat-work",new WechatWorkStrategy({
    corpId: CORP_ID,
    corpSecret: CORP_SECRET,
    agentId: agent_id,
    callbackURL: "http://localhost:3000/auth/wechat/callback",
    href: href,
    state: "state",
    scope: "snsapi_base",
  },
  function(profile, done) {
    User.findOrCreate({ userId: profile.UserId }, function (err, user) {
      return done(err, user);
    });
  },
  function getAccessToken(cb) { ... },
  function saveAccessToken(accessToken,cb){ ... }
))

Authenticate Requests

passport.authenticate()在对应的route下,注意strategy名字和passport.use()时一致。

For example

app.get('/auth/wechatwork',
  passport.authenticate('wechat-work'));

app.get('/auth/wechatwork/callback',
  passport.authenticate('wechat-work', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Additional

  • 微信企业用户验证只获得了用户基本信息,实际只获得了id,需要详细的用户信息仍需要调用微信的Users API.
{
   "UserId":"USERID",
   "DeviceId":"DEVICEID"
}