From 0d7c892cab7c39aef09427c988f402b5dbee94e6 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 19 Nov 2012 05:26:44 -0500 Subject: [PATCH] added ability to connect github development id to cloud cmd working on any host --- ChangeLog | 6 ++++++ lib/client/storage/_github.js | 16 ++++++++++++++-- lib/server/auth.js | 14 +++++++++++--- lib/server/rest.js | 6 ++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7918c960..431af874 100644 --- a/ChangeLog +++ b/ChangeLog @@ -104,6 +104,12 @@ before load menu module to. object from client to DOM module, refactored Cache object and added polyfill. +* Added ability to connect github development id, +to Cloud Commander instance working in any host, +for this all the needed to be done is: +set enveronment varibles "oauth_client_id" and +"oauth_client_secret" values from github profile. + 2012.10.01, Version 0.1.7 diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index be1b2396..ca1538fb 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -7,7 +7,9 @@ var CloudCommander, Util, DOM, $, Github, cb; var cloudcmd = CloudCommander, - API_URL = '/api/v1/auth', + APIURL = '/api/v1', + AuthURL = APIURL + '/auth', + ClientIdURL = APIURL + '/client_id', CLIENT_ID, Cache = DOM.Cache, GitHub, @@ -41,12 +43,22 @@ var CloudCommander, Util, DOM, $, Github, cb; } function setConfig(pCallBack){ + /* cloudcmd.loadConfig(function(){ var lConfig = cloudcmd.Config; CLIENT_ID = lConfig.oauth_client_id; Util.exec(pCallBack); }); + */ + + DOM.ajax({ + url : ClientIdURL, + success : function(pData){ + CLIENT_ID = pData; + Util.exec(pCallBack); + } + }); } function saveToken(pToken){ @@ -89,7 +101,7 @@ var CloudCommander, Util, DOM, $, Github, cb; DOM.ajax({ type : 'put', - url : API_URL, + url : AuthURL, data: lCode, success: function(pData){ if(pData && pData.token){ diff --git a/lib/server/auth.js b/lib/server/auth.js index 0e808144..4793de97 100644 --- a/lib/server/auth.js +++ b/lib/server/auth.js @@ -37,11 +37,19 @@ }); }; - function authenticate(pCode, pCallBack) { + var lId = Config.oauth_client_id, + lSecret = Config.oauth_client_secret, + lEnv = process.env, + + lClientId = lEnv.oauth_client_id || lId, + lClientSecret = lEnv.oauth_client_secret || lSecret; + + console.log(lEnv); + var data = qs.stringify({ - client_id : Config.oauth_client_id, - client_secret : Config.oauth_client_secret, + client_id : lClientId, + client_secret : lClientSecret, code : pCode }); diff --git a/lib/server/rest.js b/lib/server/rest.js index c70955f9..dd713770 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -96,6 +96,12 @@ break; case 'kill': process.exit(); + break; + case 'client_id': + var lEnv = process.env, + lConfig = main.config; + + lResult = lEnv.oauth_client_id || lConfig.oauth_client_id; } return lResult;