auth-config.js 2.34 KB
'use strict';
const passport = require('passport');
const WeixinStrategy = require('passport-weixin');
const SinaStrategy = require('passport-sina').Strategy;

const QQStrategy = require('passport-qq').Strategy;
const DoubanStrategy = require('passport-douban').Strategy;
const RenrenStrategy = require('passport-renren').Strategy;
const AlipayStrategy = require('../passport/models/passport-alipay').Strategy;

const config = global.yoho.config;

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

/**
 * wechat登录
 */

passport.use('home-wechat', new WeixinStrategy({
    clientID: config.thirdLogin.wechat.appID,
    clientSecret: config.thirdLogin.wechat.appSecret,
    callbackURL: `${siteUrl}/home/bind/wechat/callback`,
    requireState: true,
    scope: 'snsapi_login'
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

// sina 登录
passport.use('home-sina', new SinaStrategy({
    clientID: config.thirdLogin.sina.appID,
    clientSecret: config.thirdLogin.sina.appSecret,
    callbackURL: `${siteUrl}/home/bind/sina/callback`,
    requireState: false
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

// qq 登录
passport.use('home-qq', new QQStrategy({
    clientID: config.thirdLogin.qq.appID,
    clientSecret: config.thirdLogin.qq.appSecret,
    callbackURL: `${siteUrl}/home/bind/qq/callback`,
    requireState: false
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

// alipay 登录
passport.use('home-alipay', new AlipayStrategy({
    partner: config.thirdLogin.alipay.appID,
    key: config.thirdLogin.alipay.appSecret,
    return_url: `${siteUrl}/home/bind/alipay/callback`
}, (profile, done) => {
    done(null, profile);
}));

// douban 登录
passport.use('douban', new DoubanStrategy({
    clientID: config.thirdLogin.douban.appID,
    clientSecret: config.thirdLogin.douban.appSecret,
    callbackURL: `${siteUrl}/passport/autosign/doubanback`
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

// renren 登录
passport.use('home-renren', new RenrenStrategy({
    clientID: config.thirdLogin.renren.appID,
    clientSecret: config.thirdLogin.renren.appSecret,
    callbackURL: `${siteUrl}/home/bind/renren/callback`
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));