Skip to content

Commit 8edfbca

Browse files
Merge pull request #93 from ekonstantinidis/fix-login-bug
Fix Authentication Bug
2 parents da46ff2 + 971a0ba commit 8edfbca

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

images/press.png

29.6 KB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
},
9494
"devDependencies": {
9595
"babel-eslint": "=4.0.10",
96-
"electron-packager": "=5.0.2",
97-
"electron-prebuilt": "=0.31.0",
96+
"electron-packager": "=5.1.0",
97+
"electron-prebuilt": "=0.32.3",
9898
"eslint": "=1.2.1",
9999
"grunt": "=0.4.5",
100100
"grunt-contrib-clean": "=0.6.0",

src/js/__tests__/components/login.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@ describe('Test for Login Component', function () {
3131
);
3232
}
3333

34+
if (event == 'did-get-redirect-request') {
35+
callback(
36+
'did-get-redirect-request',
37+
'http://www.github.com/?code=123123123',
38+
'http://www.github.com/?code=123123123'
39+
);
40+
}
41+
3442
}
3543
},
3644
on: function () {
3745
return;
3846
},
3947
close: function () {
4048
return;
49+
},
50+
destroy: function () {
51+
return;
4152
}
4253
};
4354
};
@@ -141,13 +152,24 @@ describe('Test for Login Component - Callback with Error', function () {
141152
);
142153
}
143154

155+
if (event == 'did-get-redirect-request') {
156+
callback(
157+
'did-get-redirect-request',
158+
'http://www.github.com/?error=FAILURE',
159+
'http://www.github.com/?error=FAILURE'
160+
);
161+
}
162+
144163
}
145164
},
146165
on: function (event, callback) {
147166
callback();
148167
},
149168
close: function () {
150169
return;
170+
},
171+
destroy: function (argument) {
172+
return;
151173
}
152174
};
153175
};

src/js/components/login.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,30 @@ var Login = React.createClass({
2727
width: 800,
2828
height: 600,
2929
show: true,
30-
'node-integration': false
30+
'web-preferences': {
31+
'node-integration': false
32+
}
3133
});
3234
var githubUrl = 'https://github.com/login/oauth/authorize?';
3335
var authUrl = githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scope;
3436
authWindow.loadUrl(authUrl);
3537

3638
authWindow.webContents.on('will-navigate', function (event, url) {
39+
handleCallback(url);
40+
});
41+
42+
authWindow.webContents.on('did-get-redirect-request', function (event, oldUrl, newUrl) {
43+
handleCallback(newUrl);
44+
});
45+
46+
function handleCallback (url) {
3747
var raw_code = /code=([^&]*)/.exec(url) || null;
3848
var code = (raw_code && raw_code.length > 1) ? raw_code[1] : null;
3949
var error = /\?error=(.+)$/.exec(url);
4050

4151
if (code || error) {
4252
// Close the browser if code found or error
43-
authWindow.close();
53+
authWindow.destroy();
4454
}
4555

4656
// If there is a code, proceed to get token from github
@@ -50,13 +60,12 @@ var Login = React.createClass({
5060
alert('Oops! Something went wrong and we couldn\'t' +
5161
'log you in using Github. Please try again.');
5262
}
53-
54-
});
63+
}
5564

5665
// If "Done" button is pressed, hide "Loading"
5766
authWindow.on('close', function () {
58-
authWindow = null;
59-
}, false);
67+
authWindow.destroy();
68+
});
6069

6170
},
6271

0 commit comments

Comments
 (0)