Skip to content

Commit 96949d5

Browse files
committed
Merge branch 'develop'
2 parents 3f5447f + 26d4334 commit 96949d5

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oauth-js",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"main": "dist/oauth.min.js",
55
"description": "OAuth that just works",
66
"license": "apache2",

coffee/lib/oauth.coffee

+10
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ module.exports = (window, document, jQuery, navigator) ->
129129
res
130130

131131
popup: (provider, opts, callback) ->
132+
gotmessage = false
132133
getMessage = (e) ->
133134
return if e.origin isnt config.oauthd_base
134135
try
135136
wnd.close()
136137
opts.data = e.data
137138
oauthio.request.sendCallback opts, defer
139+
gotmessage = true
138140
wnd = undefined
139141
frm = undefined
140142
wndTimeout = undefined
@@ -227,9 +229,17 @@ module.exports = (window, document, jQuery, navigator) ->
227229
wnd.close()
228230
return
229231
, 1200 * 1000)
232+
230233
wnd = window.open(url, "Authorization", wnd_options)
231234
if wnd
232235
wnd.focus()
236+
interval = window.setInterval () ->
237+
if wnd == null || wnd.closed
238+
window.clearInterval interval
239+
if not gotmessage
240+
defer?.reject new Error("The popup was closed")
241+
opts.callback new Error("The popup was closed") if opts.callback and typeof opts.callback == "function"
242+
, 500
233243
else
234244
defer?.reject new Error("Could not open a popup")
235245
opts.callback new Error("Could not open a popup") if opts.callback and typeof opts.callback == "function"

dist/oauth.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module.exports = {
33
oauthd_url: "https://oauth.io",
44
oauthd_api: "https://oauth.io/api",
5-
version: "web-0.2.2",
5+
version: "web-0.2.3",
66
options: {}
77
};
88

@@ -158,7 +158,8 @@ module.exports = function(window, document, jQuery, navigator) {
158158
return res;
159159
},
160160
popup: function(provider, opts, callback) {
161-
var defer, frm, getMessage, res, url, wnd, wndTimeout, wnd_options, wnd_settings, _ref;
161+
var defer, frm, getMessage, gotmessage, interval, res, url, wnd, wndTimeout, wnd_options, wnd_settings, _ref;
162+
gotmessage = false;
162163
getMessage = function(e) {
163164
if (e.origin !== config.oauthd_base) {
164165
return;
@@ -167,7 +168,8 @@ module.exports = function(window, document, jQuery, navigator) {
167168
wnd.close();
168169
} catch (_error) {}
169170
opts.data = e.data;
170-
return oauthio.request.sendCallback(opts, defer);
171+
oauthio.request.sendCallback(opts, defer);
172+
return gotmessage = true;
171173
};
172174
wnd = void 0;
173175
frm = void 0;
@@ -301,6 +303,19 @@ module.exports = function(window, document, jQuery, navigator) {
301303
wnd = window.open(url, "Authorization", wnd_options);
302304
if (wnd) {
303305
wnd.focus();
306+
interval = window.setInterval(function() {
307+
if (wnd === null || wnd.closed) {
308+
window.clearInterval(interval);
309+
if (!gotmessage) {
310+
if (defer != null) {
311+
defer.reject(new Error("The popup was closed"));
312+
}
313+
if (opts.callback && typeof opts.callback === "function") {
314+
return opts.callback(new Error("The popup was closed"));
315+
}
316+
}
317+
}
318+
}, 500);
304319
} else {
305320
if (defer != null) {
306321
defer.reject(new Error("Could not open a popup"));

0 commit comments

Comments
 (0)