• This repository has been archived on 10/Oct/2021
  • Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

passport oauth2 strategy for weixin

passport-weixin

passport oauth2 strategy for weixin and weapp

Install

npm install passport-weixin

Usage

var passport = require('passport')
  , WeixinStrategy = require('passport-weixin')
  ;
//扫码登录
//微信官网文档:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN
passport.use('loginByWeixin',new WeixinStrategy({
  clientID: 'CLIENTID'
  , clientSecret: 'CLIENT SECRET'
  , callbackURL: 'CALLBACK URL'
  , requireState: false
  , scope: 'snsapi_login'
}, function(accessToken, refreshToken, profile, done){
  done(null, profile);
}));

//微信客户端登录
//微信官网文档:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
passport.use('loginByWeixinClient',new WeixinStrategy({
  clientID: 'CLIENTID'
  , clientSecret: 'CLIENT SECRET'
  , callbackURL: 'CALLBACK URL'
  , requireState: false
  , authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize' //[公众平台-网页授权获取用户基本信息]的授权URL 不同于[开放平台-网站应用微信登录]的授权URL
  , scope: 'snsapi_userinfo' //[公众平台-网页授权获取用户基本信息]的应用授权作用域 不同于[开放平台-网站应用微信登录]的授权URL
}, function(accessToken, refreshToken, profile, done){
  done(null, profile);
}));

路由配置如下

    //在PC端通过扫描登录,使用/auth/loginByWeixin
    app.get("/auth/loginByWeixin",
        passport.authenticate('loginByWeixin',{ successRedirect: '/test/hello',
            failureRedirect: '/login' })
    );

    //在微信客户端登录,使用/auth/loginByWeixinClient
    app.get("/auth/loginByWeixinClient",
        passport.authenticate('loginByWeixinClient',{ successRedirect: '/test/hello',
            failureRedirect: '/login' })
    );

Weapp 微信小程序

配置

test/bootstrap/providers.json

...
    "clientID": "替换为自己的小程序AppID",
    "clientSecret": "替换为自己的小程序AppSecret",
...

启动测试服务

# npm install
# npm start

HTTPS

由于小程序只支持HTTPS,需要将weapp passport server放在某HTTPS的反向代理后面才可以。类似下面2种途径

  • brew install nginx and config ...
  • docker run -v ${PWD}/nginx/conf.d:/etc/nginx/conf.d -v ${PWD}/nginx/certs:/etc/nginx/certs -d -p 443:443 nginx

License

More Repositories

1

me-pageloading

svg based pageloading for angular
JavaScript
226
star
2

dotfiles

Setup git, vim, zsh, tmux etc. using one command
Shell
108
star
3

me-lazyload

image lazyload directive for angular
JavaScript
87
star
4

fzf-zsh

[DEPRECATED]wrap fzf to use in oh-my-zsh
Shell
87
star
5

angular-require

use require in angular.js painless
JavaScript
53
star
6

kman

Koa + MongoDB + Angular.js + Node.js. A starting point for writing AngularJS apps backed by a Koa-powered node.js server.
JavaScript
51
star
7

me-animate.css

animate.css for angular
HTML
41
star
8

vue-ios-alertview

iOS7+ style alertview service for Vue
Vue
30
star
9

me-lazyimg

Yet another image lazyload directive for angular.
JavaScript
28
star
10

fis3-typescript-vue-hackernews-2.0

An example for hackernews using fis3 tool chain, typescript, vue etc.
JavaScript
22
star
11

koa-vhost

vhost for koajs
JavaScript
20
star
12

koa-validator

a koa port of express-validator
JavaScript
18
star
13

docker-ymfe-yapi

Dockerfile
17
star
14

webpack-angular-example

JavaScript
15
star
15

wyntau.github.io

the blog based on jekyll and markdown using the theme [iLotus](https://github.com/Wyntau/jekyll-theme-iLotus)
JavaScript
15
star
16

systemjs-example

a demo using System.js and Babel(or TypeScript) to load es6 modules directly in browser.
HTML
10
star
17

metalsmith-only

a file's attribute filter for metalsmith
JavaScript
6
star
18

metalsmith-except

a file's attribute `except` filter for metalsmith
JavaScript
6
star
19

metalsmith-replace

a replace plugin for metalsmith
JavaScript
6
star
20

angular-ios-alertview

iOS7+ style alertview service for angular
HTML
6
star
21

MVCObject

An implementation of Google Maps' MVCObject for Node.js and browers
JavaScript
5
star
22

angular-duoshuo

duoshuo directive for angular.js
JavaScript
4
star
23

TNotify

[DEPRECATED!] ios7+ style alert confirm and prompt service for angular
JavaScript
4
star
24

angular-ios-actionsheet

iOS7+ style actionsheet service for angular
CSS
3
star
25

jekyll-theme-apollo

A jekyll port of hexo theme apollo
CSS
3
star
26

vue-ios-actionsheet

iOS7+ style actionsheet service for Vue
Vue
3
star
27

lint-recently

lint recently git commited files
TypeScript
3
star
28

jekyll-theme-iLotus

A split jekyll fork version of [pizn/iLotus](https://github.com/pizn/iLotus). So you can just fork and start a new github pages blog like
CSS
3
star
29

koa-assign

assign property to koa context, so these properties are available in follow middlewares.
JavaScript
2
star
30

about

about me/resume
CSS
2
star
31

schematics-task

TypeScript
2
star
32

unneeded

TypeScript
2
star
33

sublime-monokai-custom

[DEPRECATED] use sublime-monokai-extended(https://github.com/jonschlinkert/sublime-monokai-extended), Modified version of Sublime Text 2 colorscheme Monokai
2
star
34

http-ng-loading-bar

A automatic loading / progress bar for http-ng
JavaScript
2
star
35

node-echo

A shell like echo for node.js with sync and async method
CoffeeScript
2
star
36

rdfind

redundant data find - code backup for rdfind(http://rdfind.pauldreik.se/)
C++
2
star
37

meblog

My Undergraduate Thesis
JavaScript
2
star
38

vue-sui-loading

Vue 2.x port of sui $.{showIndicator,hideIndicator,showPreloader,hidePreloader}
Vue
2
star
39

excel30line

a mirror of http://jsfiddle.net/ondras/hYfN3/
JavaScript
1
star
40

html5love

JavaScript
1
star
41

yeoman-generators

[Deprecated] yeoman generators include some toolchains and starters
TypeScript
1
star
42

suck

Clear your screen with suckage
C
1
star
43

koa-noop

return a noop middleware for some specific usage
JavaScript
1
star
44

cacheFactory

A stand alone cacheFactory split out from angular $cacheFactory
JavaScript
1
star
45

wyntau

1
star
46

schematics

schematics for quick start project
TypeScript
1
star
47

PhilNa2-plus

Rebirth of philna2
PHP
1
star
48

jekyll-theme-jekyllrb

SCSS
1
star
49

koa-backend

backend koa service
JavaScript
1
star
50

mocha-demo

a demo which use mocha to test in different situation
JavaScript
1
star
51

renovate-config

Shell
1
star
52

vue-sui-toast

Vue 2.x port of sui toast component http://wyntau.github.io/vue-sui-toast/example/
Vue
1
star
53

jistype

yet another istype detect library using `Object.prototype.toStirng` to get type.
CoffeeScript
1
star