-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtwitter-auth.js
42 lines (33 loc) · 1.18 KB
/
twitter-auth.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
var TwitterStrategy = require('passport-twitter').Strategy
module.exports = function (opt) {
var options = opt || {}
var seneca = this
var authPlugin = new TwitterStrategy({
consumerKey: options.apiKey,
consumerSecret: options.apiSecret,
callbackURL: options.urlhost + (options.callbackUrl || '/auth/twitter/callback')
},
function (accessToken, tokenSecret, profile, done) {
seneca.act({role: 'auth', prepare: 'twitter_login_data', accessToken: accessToken, tokenSecret: tokenSecret, profile: profile}, done)
}
)
var prepareLoginData = function (args, cb) {
var accessToken = args.accessToken
var tokenSecret = args.tokenSecret
var profile = args.profile
var data = {
nick: profile.username,
name: profile.displayName,
identifier: '' + profile.id,
credentials: {token: accessToken, secret: tokenSecret},
userdata: profile,
when: new Date().toISOString()
}
cb(null, data)
}
seneca.add({role: 'auth', prepare: 'twitter_login_data'}, prepareLoginData)
seneca.act({role: 'auth', cmd: 'register_service', service: 'twitter', plugin: authPlugin, conf: options})
return {
name: 'twitter-auth'
}
}