Showing
4 changed files
with
17 additions
and
12 deletions
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | const passport = require('passport'); | 8 | const passport = require('passport'); |
9 | -const WeixinStrategy = require('passport-weixin-plus'); | 9 | +const WeixinStrategy = require('passport-weixin'); |
10 | 10 | ||
11 | const config = require('../../config/common'); | 11 | const config = require('../../config/common'); |
12 | 12 | ||
@@ -15,14 +15,14 @@ let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : co | @@ -15,14 +15,14 @@ let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : co | ||
15 | /** | 15 | /** |
16 | * wechat登录 | 16 | * wechat登录 |
17 | */ | 17 | */ |
18 | -passport.use(new WeixinStrategy({ | ||
19 | - authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize', | ||
20 | - tokenURL: 'https://api.weixin.qq.com/sns/oauth2/access_token', | 18 | + |
19 | +passport.use('weixin', new WeixinStrategy({ | ||
21 | clientID: config.thirdLogin.wechat.appID, | 20 | clientID: config.thirdLogin.wechat.appID, |
22 | clientSecret: config.thirdLogin.wechat.appSecret, | 21 | clientSecret: config.thirdLogin.wechat.appSecret, |
23 | callbackURL: `${siteUrl}/passport/login/wechat/callback`, | 22 | callbackURL: `${siteUrl}/passport/login/wechat/callback`, |
24 | - requireState: false, | 23 | + requireState: true, |
24 | + authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize', | ||
25 | scope: 'snsapi_userinfo' | 25 | scope: 'snsapi_userinfo' |
26 | -}, (accessToken, refreshToken, profile, done) => { | 26 | +}, function(accessToken, refreshToken, profile, done) { |
27 | done(null, profile); | 27 | done(null, profile); |
28 | })); | 28 | })); |
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | 7 | ||
8 | const library = '../../../library'; | 8 | const library = '../../../library'; |
9 | const passport = require('passport'); | 9 | const passport = require('passport'); |
10 | +const uuid = require('uuid'); | ||
10 | const cookie = require(`${library}/cookie`); | 11 | const cookie = require(`${library}/cookie`); |
11 | const helpers = require(`${library}/helpers`); | 12 | const helpers = require(`${library}/helpers`); |
12 | const log = require(`${library}/logger`); | 13 | const log = require(`${library}/logger`); |
@@ -42,7 +43,6 @@ function doPassportCallback(openId, nickname, sourceType, req, res) { | @@ -42,7 +43,6 @@ function doPassportCallback(openId, nickname, sourceType, req, res) { | ||
42 | }); | 43 | }); |
43 | } | 44 | } |
44 | }).then((redirectTo) => { | 45 | }).then((redirectTo) => { |
45 | - console.log('redirectTo=', redirectTo); | ||
46 | return res.redirect(redirectTo); | 46 | return res.redirect(redirectTo); |
47 | }).catch((e) => { | 47 | }).catch((e) => { |
48 | log.error('频道页面渲染错误:' + JSON.stringify(e)); | 48 | log.error('频道页面渲染错误:' + JSON.stringify(e)); |
@@ -64,7 +64,10 @@ const wechat = { | @@ -64,7 +64,10 @@ const wechat = { | ||
64 | next(); | 64 | next(); |
65 | }, | 65 | }, |
66 | login: (req, res, next) => { | 66 | login: (req, res, next) => { |
67 | - return passport.authenticate('weixin')(req, res, next); | 67 | + console.log('1'); |
68 | + return passport.authenticate('weixin', { | ||
69 | + state: uuid.v4() | ||
70 | + })(req, res, next); | ||
68 | }, | 71 | }, |
69 | callback: (req, res, next) => { | 72 | callback: (req, res, next) => { |
70 | passport.authenticate('weixin', (err, user) => { | 73 | passport.authenticate('weixin', (err, user) => { |
@@ -72,8 +75,9 @@ const wechat = { | @@ -72,8 +75,9 @@ const wechat = { | ||
72 | log.error(`wechat authenticate error : ${JSON.stringify(err)}`); | 75 | log.error(`wechat authenticate error : ${JSON.stringify(err)}`); |
73 | return res.redirect(loginPage); | 76 | return res.redirect(loginPage); |
74 | } | 77 | } |
75 | - let nickname = user.displayName || user._json.nickname; | ||
76 | - let openId = user.id || user._json.unionid; | 78 | + console.log(user); |
79 | + let nickname = user._json.nickname || user.displayName; | ||
80 | + let openId = user._json.unionid || user.id; | ||
77 | 81 | ||
78 | doPassportCallback(openId, nickname, 'wechat', req, res); | 82 | doPassportCallback(openId, nickname, 'wechat', req, res); |
79 | })(req, res, next); | 83 | })(req, res, next); |
@@ -13,8 +13,8 @@ module.exports = { | @@ -13,8 +13,8 @@ module.exports = { | ||
13 | port: 6001, | 13 | port: 6001, |
14 | siteUrl: '//m.yohobuy.com', | 14 | siteUrl: '//m.yohobuy.com', |
15 | domains: { | 15 | domains: { |
16 | - api: 'http://devapi.yoho.cn:58078/', | ||
17 | - service: 'http://devservice.yoho.cn:58077/', | 16 | + api: 'http://testapi.yoho.cn:28078/', |
17 | + service: 'http://testservice.yoho.cn:28077/', | ||
18 | search: 'http://192.168.10.64:8080/yohosearch/' | 18 | search: 'http://192.168.10.64:8080/yohosearch/' |
19 | }, | 19 | }, |
20 | useOneapm: false, | 20 | useOneapm: false, |
@@ -44,6 +44,7 @@ | @@ -44,6 +44,7 @@ | ||
44 | "morgan": "^1.7.0", | 44 | "morgan": "^1.7.0", |
45 | "oneapm": "^1.2.20", | 45 | "oneapm": "^1.2.20", |
46 | "passport": "^0.3.2", | 46 | "passport": "^0.3.2", |
47 | + "passport-weixin": "^0.1.0", | ||
47 | "passport-weixin-plus": "0.0.4", | 48 | "passport-weixin-plus": "0.0.4", |
48 | "request-promise": "^3.0.0", | 49 | "request-promise": "^3.0.0", |
49 | "serve-favicon": "^2.3.0", | 50 | "serve-favicon": "^2.3.0", |
-
Please register or login to post a comment