-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathgithub.js
More file actions
50 lines (44 loc) · 1.41 KB
/
github.js
File metadata and controls
50 lines (44 loc) · 1.41 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
var oauthModule = require('./oauth2');
var github = module.exports =
oauthModule.submodule('github')
.configurable({
scope: 'specify types of access: (no scope), user, public_repo, repo, gist'
})
.oauthHost('https://github.com')
.apiHost('https://api.github.com')
.authPath('/login/oauth/authorize')
.accessTokenPath('/login/oauth/access_token')
.entryPath('/auth/github')
.callbackPath('/auth/github/callback')
.authQueryParam('scope', function () {
return this._scope && this.scope();
})
.fetchOAuthUser( function (accessToken) {
var p = this.Promise();
this.oauth.get(this.apiHost() + '/user', accessToken, function (err, data) {
if (err) return p.fail(err);
var oauthUser = JSON.parse(data);
p.fulfill(oauthUser);
})
return p;
})
.moduleErrback( function (err, seqValues) {
if (err instanceof Error) {
var next = seqValues.next;
return next(err);
} else if (err.extra) {
var ghResponse = err.extra.res
, serverResponse = seqValues.res;
serverResponse.writeHead(
ghResponse.statusCode
, ghResponse.headers);
serverResponse.end(err.extra.data);
} else if (err.statusCode) {
var serverResponse = seqValues.res;
serverResponse.writeHead(err.statusCode);
serverResponse.end(err.data);
} else {
console.error(err);
throw new Error('Unsupported error type');
}
});