-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathopenidconnect.strategy.config.js
46 lines (42 loc) · 1.45 KB
/
openidconnect.strategy.config.js
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
'use strict';
/**
* Module dependencies.
*/
var passport = require('passport'),
path = require('path'),
OpenIDConnect = require('passport-openidconnect').Strategy,
users = require(path.resolve('./modules/users/server/controllers/users.server.controller'));
module.exports = function (userAuth) {
console.log('RUNNING WITH: ' + userAuth.provider);
passport.use(new OpenIDConnect({
authorizationURL: userAuth.authURL,
tokenURL: userAuth.tokenURL,
userInfoURL: userAuth.userInfoURL,
clientID: userAuth.clientId,
clientSecret: userAuth.clientSecret,
callbackURL: userAuth.callbackURL,
scope: 'openid profile email',
passReqToCallback: true
},
function (req, accessToken, refreshToken, profile, done) {
console.log(profile);
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;
// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile._json.email,
username: profile.username,
provider: userAuth.provider,
providerIdentifierField: 'user_id',
providerData: providerData
};
// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
};