Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
william26 committed Aug 4, 2014
2 parents 3f5447f + 26d4334 commit 96949d5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oauth-js",
"version": "0.2.2",
"version": "0.2.3",
"main": "dist/oauth.min.js",
"description": "OAuth that just works",
"license": "apache2",
Expand Down
10 changes: 10 additions & 0 deletions coffee/lib/oauth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ module.exports = (window, document, jQuery, navigator) ->
res

popup: (provider, opts, callback) ->
gotmessage = false
getMessage = (e) ->
return if e.origin isnt config.oauthd_base
try
wnd.close()
opts.data = e.data
oauthio.request.sendCallback opts, defer
gotmessage = true
wnd = undefined
frm = undefined
wndTimeout = undefined
Expand Down Expand Up @@ -227,9 +229,17 @@ module.exports = (window, document, jQuery, navigator) ->
wnd.close()
return
, 1200 * 1000)

wnd = window.open(url, "Authorization", wnd_options)
if wnd
wnd.focus()
interval = window.setInterval () ->
if wnd == null || wnd.closed
window.clearInterval interval
if not gotmessage
defer?.reject new Error("The popup was closed")
opts.callback new Error("The popup was closed") if opts.callback and typeof opts.callback == "function"
, 500
else
defer?.reject new Error("Could not open a popup")
opts.callback new Error("Could not open a popup") if opts.callback and typeof opts.callback == "function"
Expand Down
21 changes: 18 additions & 3 deletions dist/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
oauthd_url: "https://oauth.io",
oauthd_api: "https://oauth.io/api",
version: "web-0.2.2",
version: "web-0.2.3",
options: {}
};

Expand Down Expand Up @@ -158,7 +158,8 @@ module.exports = function(window, document, jQuery, navigator) {
return res;
},
popup: function(provider, opts, callback) {
var defer, frm, getMessage, res, url, wnd, wndTimeout, wnd_options, wnd_settings, _ref;
var defer, frm, getMessage, gotmessage, interval, res, url, wnd, wndTimeout, wnd_options, wnd_settings, _ref;
gotmessage = false;
getMessage = function(e) {
if (e.origin !== config.oauthd_base) {
return;
Expand All @@ -167,7 +168,8 @@ module.exports = function(window, document, jQuery, navigator) {
wnd.close();
} catch (_error) {}
opts.data = e.data;
return oauthio.request.sendCallback(opts, defer);
oauthio.request.sendCallback(opts, defer);
return gotmessage = true;
};
wnd = void 0;
frm = void 0;
Expand Down Expand Up @@ -301,6 +303,19 @@ module.exports = function(window, document, jQuery, navigator) {
wnd = window.open(url, "Authorization", wnd_options);
if (wnd) {
wnd.focus();
interval = window.setInterval(function() {
if (wnd === null || wnd.closed) {
window.clearInterval(interval);
if (!gotmessage) {
if (defer != null) {
defer.reject(new Error("The popup was closed"));
}
if (opts.callback && typeof opts.callback === "function") {
return opts.callback(new Error("The popup was closed"));
}
}
}
}, 500);
} else {
if (defer != null) {
defer.reject(new Error("Could not open a popup"));
Expand Down
Loading

0 comments on commit 96949d5

Please sign in to comment.