From b14954ab7cc17252316652878ae381c9e18f8147 Mon Sep 17 00:00:00 2001
From: Rodrigo Nascimento <rodrigoknascimento@gmail.com>
Date: Wed, 23 Sep 2015 10:46:35 -0300
Subject: [PATCH] Close #861; Fix Gitlab oAuth url from API_Gitlab_URL

---
 .../custom_oauth_client.coffee                  | 17 ++++++++++-------
 packages/rocketchat-gitlab/common.coffee        |  7 +++++--
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/packages/rocketchat-custom-oauth/custom_oauth_client.coffee b/packages/rocketchat-custom-oauth/custom_oauth_client.coffee
index 72ed354f4200..4dafb22e3e0d 100644
--- a/packages/rocketchat-custom-oauth/custom_oauth_client.coffee
+++ b/packages/rocketchat-custom-oauth/custom_oauth_client.coffee
@@ -8,6 +8,13 @@ class CustomOAuth
 		if not Match.test @name, String
 			return throw new Meteor.Error 'CustomOAuth: Name is required and must be String'
 
+		@configure options
+
+		Accounts.oauth.registerService @name
+
+		@configureLogin()
+
+	configure: (options) ->
 		if not Match.test options, Object
 			return throw new Meteor.Error 'CustomOAuth: Options is required and must be Object'
 
@@ -20,13 +27,9 @@ class CustomOAuth
 		@serverURL = options.serverURL
 
 		if not /^https?:\/\/.+/.test options.authorizePath
-			options.authorizePath = @serverURL + options.authorizePath
-
-		@authorizePath = options.authorizePath
-
-		Accounts.oauth.registerService @name
-
-		@configureLogin()
+			@authorizePath = @serverURL + options.authorizePath
+		else
+			@authorizePath = options.authorizePath
 
 	configureLogin: ->
 		self = @
diff --git a/packages/rocketchat-gitlab/common.coffee b/packages/rocketchat-gitlab/common.coffee
index d3654a9ab46b..e6980e1115e1 100644
--- a/packages/rocketchat-gitlab/common.coffee
+++ b/packages/rocketchat-gitlab/common.coffee
@@ -1,11 +1,14 @@
-Gitlab = new CustomOAuth 'gitlab',
+config =
 	serverURL: 'https://gitlab.com'
 	identityPath: '/api/v3/user'
 	addAutopublishFields:
 		forLoggedInUser: ['services.gitlab']
 		forOtherUsers: ['services.gitlab.username']
 
+Gitlab = new CustomOAuth 'gitlab', config
+
 Meteor.startup ->
 	Tracker.autorun ->
 		if RocketChat.settings.get 'API_Gitlab_URL'
-			Gitlab.serverURL = RocketChat.settings.get 'API_Gitlab_URL'
+			config.serverURL = RocketChat.settings.get 'API_Gitlab_URL'
+			Gitlab.configure config