From 63c345cf4c31ce257d4c2ab5bf4bc6c552d1074a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Thu, 25 Sep 2014 14:46:46 +0100 Subject: [PATCH] Allow github to be used with GitHub Enterprise --- README.md | 1 + lib/services/github.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95de764..bfac8b1 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/services/github.js b/lib/services/github.js index 311ad77..5d174fa 100644 --- a/lib/services/github.js +++ b/lib/services/github.js @@ -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, @@ -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, @@ -25,8 +30,8 @@ function Github(options) { } this.user = { - host: "api.github.com", - path: "/user", + host: apiHost, + path: apiPath + "/user", query: {} }