From 73e265d8fd050ae3daa67472b4465a5c49d68910 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 20 Apr 2019 15:18:33 +0300 Subject: Include to Wekan packages directory contents, so that meteor command would build all directly. This also simplifies build scripts. Thanks to xet7 ! --- packages/meteor-accounts-cas/cas_client_cordova.js | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/meteor-accounts-cas/cas_client_cordova.js (limited to 'packages/meteor-accounts-cas/cas_client_cordova.js') diff --git a/packages/meteor-accounts-cas/cas_client_cordova.js b/packages/meteor-accounts-cas/cas_client_cordova.js new file mode 100644 index 00000000..c7f95b50 --- /dev/null +++ b/packages/meteor-accounts-cas/cas_client_cordova.js @@ -0,0 +1,71 @@ + +Meteor.loginWithCas = function(callback) { + + var credentialToken = Random.id(); + + if (!Meteor.settings.public && + !Meteor.settings.public.cas && + !Meteor.settings.public.cas.loginUrl) { + return; + } + + var settings = Meteor.settings.public.cas; + + var loginUrl = settings.loginUrl + + "?" + (settings.service || "service") + "=" + + Meteor.absoluteUrl('_cas/') + + credentialToken; + + + var fail = function (err) { + Meteor._debug("Error from OAuth popup: " + JSON.stringify(err)); + }; + + // When running on an android device, we sometimes see the + // `pageLoaded` callback fire twice for the final page in the OAuth + // popup, even though the page only loads once. This is maybe an + // Android bug or maybe something intentional about how onPageFinished + // works that we don't understand and isn't well-documented. + var oauthFinished = false; + + var pageLoaded = function (event) { + if (oauthFinished) { + return; + } + + if (event.url.indexOf(Meteor.absoluteUrl('_cas')) === 0) { + + oauthFinished = true; + + // On iOS, this seems to prevent "Warning: Attempt to dismiss from + // view controller while a presentation + // or dismiss is in progress". My guess is that the last + // navigation of the OAuth popup is still in progress while we try + // to close the popup. See + // https://issues.apache.org/jira/browse/CB-2285. + // + // XXX Can we make this timeout smaller? + setTimeout(function () { + popup.close(); + // check auth on server. + Accounts.callLoginMethod({ + methodArguments: [{ cas: { credentialToken: credentialToken } }], + userCallback: callback + }); + }, 100); + } + }; + + var onExit = function () { + popup.removeEventListener('loadstop', pageLoaded); + popup.removeEventListener('loaderror', fail); + popup.removeEventListener('exit', onExit); + }; + + var popup = window.open(loginUrl, '_blank', 'location=no,hidden=no'); + popup.addEventListener('loadstop', pageLoaded); + popup.addEventListener('loaderror', fail); + popup.addEventListener('exit', onExit); + popup.show(); + +}; \ No newline at end of file -- cgit v1.2.3-1-g7c22