auth.js 853 Bytes
/**
 * passport 验证策略注册
 * @author: jiangfeng<jeff.jiang@yoho.cn>
 * @date: 2016/5/31
 */

'use strict';
const passport = require('passport');
const WeixinStrategy = require('passport-weixin-plus');

const config = require('../../config/common');

let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;

/**
 * wechat登录
 */
passport.use(new WeixinStrategy({
    authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize',
    tokenURL: 'https://api.weixin.qq.com/sns/oauth2/access_token',
    clientID: config.thirdLogin.wechat.appID,
    clientSecret: config.thirdLogin.wechat.appSecret,
    callbackURL: `${siteUrl}/passport/login/wechat/callback`,
    requireState: false,
    scope: 'snsapi_userinfo'
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));