This repository was archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathOpenID.js
73 lines (58 loc) · 1.69 KB
/
OpenID.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Module dependencies
*/
var Strategy = require('passport-openid').Strategy
var util = require('util')
var User = require('../../models/User')
/**
* OpenIDStrategy
*
* Provider is an object defining the details of the authentication API.
* Client is an object containing provider registration info and options.
* Verify is the Passport callback to invoke after authenticating
*/
function OpenIDStrategy (provider, verify) {
this.provider = provider
this.name = provider.id
if (!provider.returnURL) {
provider.returnURL = provider.callbackURL
}
Strategy.call(this, provider, verify)
this.client = provider
this.verify = verify
}
util.inherits(OpenIDStrategy, Strategy)
/**
* Verifier
*/
function verifier (req, identifier, userInfo, done) {
// Raw OpenID Provider response should be stored
// for consistency with other protocols.
var auth = {
id: req.query['openid.identity'],
req_query: req.query
}
userInfo.id = req.query['openid.identity']
userInfo.name = req.query['openid.ext2.value.fullname']
userInfo.givenName = req.query['openid.ext2.value.firstname']
userInfo.familyName = req.query['openid.ext2.value.lastname']
userInfo.email = req.query['openid.ext2.value.email']
User.connect(req, auth, userInfo, function (err, user) {
if (err) { return done(err) }
done(null, user)
})
}
OpenIDStrategy.verifier = verifier
/**
* Initialize - note provider === configuration
*/
function initialize (provider, configuration) {
configuration.profile = true
configuration.passReqToCallback = true
return new OpenIDStrategy(configuration, verifier)
}
OpenIDStrategy.initialize = initialize
/**
* Exports
*/
module.exports = OpenIDStrategy