Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Allow github to be used with GitHub Enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 25, 2014
1 parent ac54e69 commit 63c345c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -430,6 +430,7 @@ Options:
- `redirect_uri` (optional): Alternative redirect url.
- `scope` (optional): the scopes requested by your application, as explained [here](http://developer.github.com/v3/oauth/#scopes).
- `state` (optional): Unguessable random string.
- `url` (optional): URL to github. Specify this to use with GitHub Enterprise.

Example:

Expand Down
15 changes: 10 additions & 5 deletions lib/services/github.js
Expand Up @@ -2,9 +2,14 @@ var OAuth2 = require("./oauth2")
, util = require("util")

function Github(options) {
var url = require('url').parse(options.url || 'https://github.com')
var protocol = url.protocol.split(':')[0]
var apiHost = url.host === 'github.com' ? 'api.github.com' : url.host
var apiPath = url.host === 'github.com' ? '' : '/api/v3'

this.code = {
protocol: "https",
host: "github.com",
protocol: protocol,
host: url.host,
pathname: "/login/oauth/authorize",
query: {
client_id: options.id,
Expand All @@ -16,7 +21,7 @@ function Github(options) {

this.token = {
method: "POST",
host: "github.com",
host: url.host,
path: "/login/oauth/access_token",
query: {
client_id: options.id,
Expand All @@ -25,8 +30,8 @@ function Github(options) {
}

this.user = {
host: "api.github.com",
path: "/user",
host: apiHost,
path: apiPath + "/user",
query: {}
}

Expand Down

0 comments on commit 63c345c

Please sign in to comment.