mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(auth) authenticate
This commit is contained in:
parent
409d1a1c53
commit
95c93c03d7
1 changed files with 8 additions and 9 deletions
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
https = main.https,
|
||||
qs = main.querystring,
|
||||
pipe = main.pipe,
|
||||
|
||||
Modules = main.modules,
|
||||
Util = main.util,
|
||||
|
|
@ -48,7 +49,7 @@
|
|||
};
|
||||
|
||||
function authenticate(code, callback) {
|
||||
var body, req,
|
||||
var req,
|
||||
storage = Util.findObjByNameInArr(Modules, 'storage'),
|
||||
github = Util.findObjByNameInArr(storage, 'GitHub'),
|
||||
|
||||
|
|
@ -67,19 +68,17 @@
|
|||
|
||||
Util.log(clientId, clientSecret, data);
|
||||
|
||||
GithubAuth.headers = { 'content-length': data.length };
|
||||
|
||||
body = "",
|
||||
req = https.request(GithubAuth, function(res) {
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function (chunk) { body += chunk; });
|
||||
res.on('end', function() {
|
||||
Util.exec(pCallBack, qs.parse(body).access_token);
|
||||
GithubAuth.headers = { 'content-length': data.length };
|
||||
|
||||
req = https.request(GithubAuth, function(res) {
|
||||
pipe.getBody(res, function(body) {
|
||||
Util.exec(callback, qs.parse(body).access_token);
|
||||
});
|
||||
});
|
||||
|
||||
req.write(data);
|
||||
req.end();
|
||||
|
||||
req.on('error', function(e) {
|
||||
Util.exec(callback, e.message);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue