-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathpassportLoader.js
More file actions
67 lines (58 loc) · 2.06 KB
/
passportLoader.js
File metadata and controls
67 lines (58 loc) · 2.06 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
// Define some pseudo module globals
var isPro = require('../libs/debug').isPro;
var isDev = require('../libs/debug').isDev;
var isDbg = require('../libs/debug').isDbg;
//
var passport = require('passport');
var nil = require('../libs/helpers').nil;
var AUTH_CALLBACK_BASE_URL = 'http://localhost:' + (process.env.PORT || 8080);
if (isPro)
AUTH_CALLBACK_BASE_URL = 'https://openuserjs.org';
if (process.env.AUTH_CALLBACK_BASE_URL)
AUTH_CALLBACK_BASE_URL = process.env.AUTH_CALLBACK_BASE_URL;
exports.strategyInstances = nil();
// This will load a single passport
// Notice it is general so it can load any passport strategy
exports.loadPassport = function (aStrategy) {
var requireStr = 'passport-' + aStrategy.name
+ (aStrategy.name === 'google' ? '-oauth' : '');
var PassportStrategy = require(requireStr)[
aStrategy.name === 'google' ? 'OAuth2Strategy' : 'Strategy'];
var instance = null;
var authParams = null;
if (aStrategy.openid) {
instance = new PassportStrategy(
{
returnURL: AUTH_CALLBACK_BASE_URL + '/auth/' + aStrategy.name + '/callback/',
realm: AUTH_CALLBACK_BASE_URL + '/',
audience: AUTH_CALLBACK_BASE_URL,
profile: false,
stateless: true
},
function () { } // we replace this callback later (_verify)
);
} else {
instance = new PassportStrategy(
{
consumerKey: aStrategy.id,
consumerSecret: aStrategy.key,
clientID: aStrategy.id,
clientSecret: aStrategy.key,
state: 'a bullshit string reddit requires',
callbackURL: AUTH_CALLBACK_BASE_URL + '/auth/' + aStrategy.name + '/callback/'
},
function () { } // we replace this callback later (_verify)
);
}
if (aStrategy.name === 'google') {
authParams = instance.authorizationParams;
instance.authorizationParams = function() {
var val = authParams.apply(this, arguments);
val['openid.realm'] = AUTH_CALLBACK_BASE_URL + '/';
return val;
};
}
exports.strategyInstances[aStrategy.name] = instance;
passport.use(instance);
};