auth.js
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* passport 验证策略注册
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/5/31
*/
'use strict';
const passport = require('passport');
const WeixinStrategy = require('passport-weixin');
const SinaStrategy = require('passport-sina').Strategy;
const QQStrategy = require('passport-qq').Strategy;
const config = global.yoho.config;
let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;
let weChatUrl = `${siteUrl}/passport/login/wechat/callback`;
let sinaUrl = `${siteUrl}/passport/login/sina/callback`;
// wechat 登录
passport.use('weixin', new WeixinStrategy({
clientID: 'wx75e5a7c0c88e45c2',
clientSecret: 'ce21ae4a3f93852279175a167e54509b',
callbackURL: `//m.yohobuy.com/passport/login/wechat/redirect?redirectUrl=${weChatUrl}`,
requireState: true,
authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize',
scope: 'snsapi_userinfo'
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
// sina 登录
passport.use('sina', new SinaStrategy({
clientID: '3739328910',
clientSecret: '9d44cded26d048e23089e5e975c93df1',
callbackURL: `//m.yohobuy.com/passport/login/sina/redirect?redirectUrl=${sinaUrl}`,
requireState: false
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
// qq 登录
passport.use('qq', new QQStrategy({
clientID: '100229394',
clientSecret: 'c0af9c29e0900813028c2ccb42021792',
callbackURL: `${siteUrl}/passport/login/qq/callback`,
requireState: false
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));