Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Commit 93944cb

Browse files
committed
Merge pull request #231 from aubergene/master
Support Github enterprise for authentication
2 parents 6e0b739 + ba3280b commit 93944cb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ var http = require('http')
145145
// Build the authorization config and url
146146
var auth_url = github.auth.config({
147147
id: 'mygithubclientid',
148-
secret: 'mygithubclientsecret'
148+
secret: 'mygithubclientsecret',
149+
apiUrl: 'https://optional-internal-github-enterprise/api/v3',
150+
webUrl: 'https://optional-internal-github-enterprise'
149151
}).login(['user', 'repo', 'gist']);
150152

151153
// Store info to verify against CSRF
@@ -403,7 +405,7 @@ ghme.issues({
403405
per_page: 100,
404406
filter: 'assigned',
405407
state: 'open',
406-
sort: 'created'
408+
sort: 'created'
407409
}, callback); //array of issues
408410
```
409411

lib/octonode/auth.js

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/octonode/auth.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ auth = module.exports =
2626
else
2727
throw new Error('No working mode recognized')
2828
@options = options
29+
@options.apiUrl ||= "https://api.github.com"
30+
@options.webUrl ||= "https://github.com"
2931
return this
3032

3133
revoke: (id, callback) ->
3234
if @mode == @modes.cli
3335
options =
34-
url: url.parse "https://api.github.com/authorizations/#{id}"
36+
url: url.parse "#{@options.apiUrl}/authorizations/#{id}"
3537
method: 'DELETE'
3638
headers:
3739
'User-Agent': 'octonode/0.3 (https://github.com/pksunkara/octonode) terminal/0.0'
@@ -48,7 +50,7 @@ auth = module.exports =
4850
else
4951
scopes = JSON.stringify scopes
5052
options =
51-
url: url.parse "https://api.github.com/authorizations"
53+
url: url.parse "#{@options.apiUrl}/authorizations"
5254
method: 'POST'
5355
body: scopes
5456
headers:
@@ -70,15 +72,15 @@ auth = module.exports =
7072
if res.statusCode is 201 then callback(null, body.id, body.token) else callback(new Error(body.message))
7173
else if @mode == @modes.web
7274
if scopes instanceof Array
73-
uri = 'https://github.com/login/oauth/authorize'
75+
uri = "#{@options.webUrl}/login/oauth/authorize"
7476
uri+= "?client_id=#{@options.id}"
7577
uri+= "&state=#{randomstring.generate()}"
7678
uri+= "&scope=#{scopes.join(',')}"
7779
if @options.redirect_uri then uri+= "&redirect_uri=#{@options.redirect_uri}"
7880
return uri
7981
else
8082
request
81-
url: 'https://github.com/login/oauth/access_token'
83+
url: "#{@options.webUrl}/login/oauth/access_token"
8284
method: 'POST'
8385
body: qs.stringify
8486
code: scopes

0 commit comments

Comments
 (0)