-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
61 lines (51 loc) · 1.77 KB
/
index.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
const OAuthStrategy = require('passport-oauth1')
const defaultOptions = {
requestTokenURL: 'https://trello.com/1/OAuthGetRequestToken',
accessTokenURL: 'https://trello.com/1/OAuthGetAccessToken',
userAuthorizationURL: 'https://trello.com/1/OAuthAuthorizeToken',
profileURL: 'https://trello.com/1/members/me',
sessionKey: 'oauth:trello',
}
class TrelloStrategy extends OAuthStrategy {
name = 'trello'
constructor(passedOptions, verify) {
const options = Object.assign(defaultOptions, passedOptions || {})
super(options, verify)
this.options = options
}
userProfile(token, tokenSecret, params, done) {
this._oauth.get(this.options.profileURL, token, tokenSecret, function (err, body, res) {
if (err) {
return done(new InternalOAuthError('failed to fetch user profile', err))
}
try {
var json = JSON.parse(body)
var profile = {
provider: 'trello'
}
profile.id = json.id
profile.displayName = json.fullName
profile.emails = [{
value: json.email,
type: 'work'
}]
profile._raw = body
profile._json = json
done(null, profile)
} catch (e) {
done(e)
}
})
}
userAuthorizationParams(passedOptions) {
const options = Object.assign(this.options.trelloParams || {}, passedOptions || {})
if (options.scope && Array.isArray(options.scope)) {
options.scope = options.scope.join(',')
}
return options
}
}
module.exports = {
version: '1.0.0',
Strategy: TrelloStrategy
}