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

Commit

Permalink
Support Github enterprise for authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
aubergene committed Mar 7, 2016
1 parent 6e0b739 commit ba3280b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ var http = require('http')
// Build the authorization config and url
var auth_url = github.auth.config({
id: 'mygithubclientid',
secret: 'mygithubclientsecret'
secret: 'mygithubclientsecret',
apiUrl: 'https://optional-internal-github-enterprise/api/v3',
webUrl: 'https://optional-internal-github-enterprise'
}).login(['user', 'repo', 'gist']);

// Store info to verify against CSRF
Expand Down Expand Up @@ -403,7 +405,7 @@ ghme.issues({
per_page: 100,
filter: 'assigned',
state: 'open',
sort: 'created'
sort: 'created'
}, callback); //array of issues
```

Expand Down
11 changes: 7 additions & 4 deletions lib/octonode/auth.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/octonode/auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ auth = module.exports =
else
throw new Error('No working mode recognized')
@options = options
@options.apiUrl ||= "https://api.github.com"
@options.webUrl ||= "https://github.com"
return this

revoke: (id, callback) ->
if @mode == @modes.cli
options =
url: url.parse "https://api.github.com/authorizations/#{id}"
url: url.parse "#{@options.apiUrl}/authorizations/#{id}"
method: 'DELETE'
headers:
'User-Agent': 'octonode/0.3 (https://github.com/pksunkara/octonode) terminal/0.0'
Expand All @@ -48,7 +50,7 @@ auth = module.exports =
else
scopes = JSON.stringify scopes
options =
url: url.parse "https://api.github.com/authorizations"
url: url.parse "#{@options.apiUrl}/authorizations"
method: 'POST'
body: scopes
headers:
Expand All @@ -70,15 +72,15 @@ auth = module.exports =
if res.statusCode is 201 then callback(null, body.id, body.token) else callback(new Error(body.message))
else if @mode == @modes.web
if scopes instanceof Array
uri = 'https://github.com/login/oauth/authorize'
uri = "#{@options.webUrl}/login/oauth/authorize"
uri+= "?client_id=#{@options.id}"
uri+= "&state=#{randomstring.generate()}"
uri+= "&scope=#{scopes.join(',')}"
if @options.redirect_uri then uri+= "&redirect_uri=#{@options.redirect_uri}"
return uri
else
request
url: 'https://github.com/login/oauth/access_token'
url: "#{@options.webUrl}/login/oauth/access_token"
method: 'POST'
body: qs.stringify
code: scopes
Expand Down

0 comments on commit ba3280b

Please sign in to comment.