From 5e81bcf3d62439eb78e76f8fb98509896fc97867 Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Fri, 11 Dec 2015 22:11:58 -0500 Subject: [PATCH 1/3] [OAuth2] Use redirects instead of origin --- manifest.webapp | 7 +- modules/oauth2/dropbox.svg | 20 +++++ modules/oauth2/dropbox_oauth2.js | 2 + modules/oauth2/index.html | 35 +++++++++ .../dropbox_authdriver_firefoxos_receiver.js | 78 +++++++++++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 modules/oauth2/dropbox.svg create mode 100644 modules/oauth2/dropbox_oauth2.js create mode 100644 modules/oauth2/index.html create mode 100644 scripts/cloud/dropbox_authdriver_firefoxos_receiver.js diff --git a/manifest.webapp b/manifest.webapp index 85ae381..488a78c 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -4,7 +4,6 @@ "version": "0.5", "type": "privileged", "launch_path": "/index.html", - "origin": "app://firetext", "developer": { "name": "Airborn OS", "url": "https://www.airbornos.com/" @@ -94,6 +93,12 @@ "access": "readwrite" } }, + "redirects": [ + { + "from": "https://firetext-server.herokuapp.com/auth/dropbox/oauth2/", + "to": "/modules/oauth2/index.html" + } + ], "activities": { "open": { "href": "./index.html", diff --git a/modules/oauth2/dropbox.svg b/modules/oauth2/dropbox.svg new file mode 100644 index 0000000..bc3763a --- /dev/null +++ b/modules/oauth2/dropbox.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/modules/oauth2/dropbox_oauth2.js b/modules/oauth2/dropbox_oauth2.js new file mode 100644 index 0000000..2f537db --- /dev/null +++ b/modules/oauth2/dropbox_oauth2.js @@ -0,0 +1,2 @@ +// Launch OAuth Receiver with internal app flag +Dropbox.AuthDriver.FFOSPopup.oauthReceiver(true); \ No newline at end of file diff --git a/modules/oauth2/index.html b/modules/oauth2/index.html new file mode 100644 index 0000000..9cf07ac --- /dev/null +++ b/modules/oauth2/index.html @@ -0,0 +1,35 @@ + + + + + + Dropbox Auth + + + + + + +
+ Dropbox Logo +

You can now use Firetext with Dropbox!

+

This window should close automatically in a few seconds...

+
+ + \ No newline at end of file diff --git a/scripts/cloud/dropbox_authdriver_firefoxos_receiver.js b/scripts/cloud/dropbox_authdriver_firefoxos_receiver.js new file mode 100644 index 0000000..402d685 --- /dev/null +++ b/scripts/cloud/dropbox_authdriver_firefoxos_receiver.js @@ -0,0 +1,78 @@ +/* +* Firefox OS Popup Dropbox Receiver +* Copyright (C) Codexa Organization. +*/ + +if (Dropbox && Dropbox.AuthDriver) { + Dropbox.AuthDriver.FFOSPopup = (function(superClass) { + var allowedOrigins = ["https://codexa.github.io", "http://firetext.codexa.bugs3.com", "localhost"]; + + function FFOSPopup() { + } + + FFOSPopup.locationOrigin = function(location) { + var match; + match = /^(file:\/\/[^\?\#]*)/.exec(location); + if (match) { + return "file"; + } + + match = /^([^\:]+\:\/\/localhost(:[0-9]*){0,1}([\/]|$))/.exec(location); + if (match) { + return "localhost"; + } + + match = /^([^\:]+\:\/\/[^\/\?\#]*)/.exec(location); + if (match) { + return match[1]; + } + return location; + }; + + FFOSPopup.oauthReceiver = function(inApp) { + window.addEventListener('load', function() { + var frameError, getOriginMessage, ieError, message, opener, pageUrl, receiveMessage; + pageUrl = window.location.href; + getOriginMessage = JSON.stringify({ + _dropboxjs_needs_origin: true + }); + message = JSON.stringify({ + _dropboxjs_oauth_info: pageUrl + }); + Dropbox.AuthDriver.BrowserBase.cleanupLocation(); + opener = window.opener; + if (window.parent !== window.top) { + opener || (opener = window.parent); + } + if (opener) { + receiveMessage = function(e) { + if (e.source === opener && + (allowedOrigins.indexOf(Dropbox.AuthDriver.FFOSPopup.locationOrigin(e.origin)) !== -1 || + inApp)) { + opener.postMessage(message, e.origin); + window.close(); + } + }; + window.addEventListener('message', receiveMessage, false); + try { + opener.postMessage(getOriginMessage, "*"); + } catch (_error) { + ieError = _error; + } + try { + opener.Dropbox.AuthDriver.FFOSPopup.onMessage.dispatch(message); + window.close(); + } catch (_error) { + frameError = _error; + } + } + }); + }; + + FFOSPopup.onMessage = new Dropbox.Util.EventSource; + + return FFOSPopup; + })(Dropbox.AuthDriver.BrowserBase); +} else { + console.log("Dropbox.js is not present."); +} \ No newline at end of file From f8e70267eba1ee31495233e9f1a882e4aebf199c Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Fri, 11 Dec 2015 22:43:24 -0500 Subject: [PATCH 2/3] Exclude oauth2 module requirements from build concatenation --- builder/build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/build b/builder/build index d4ace93..9d1cf79 100755 --- a/builder/build +++ b/builder/build @@ -18,6 +18,8 @@ cp ../manifest.webapp ../build mkdir -p ../build/scripts/lib mkdir -p ../build/scripts/parsers/odt.js/lib cp ../scripts/messages.js ../build/scripts +cp ../scripts/cloud/dropbox.min.js ../build/scripts/cloud +cp ../scripts/cloud/dropbox_authdriver_firefoxos_receiver.js ../build/scripts/cloud cp ../scripts/lib/jszip.js ../build/scripts/lib cp ../scripts/lib/jszip-deflate.js ../build/scripts/lib cp ../scripts/lib/jszip-inflate.js ../build/scripts/lib From b0c62026bbe800c012265639ad5433e0b5477c25 Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Fri, 11 Dec 2015 23:02:57 -0500 Subject: [PATCH 3/3] Create scripts/cloud directory in build --- builder/build | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/build b/builder/build index 9d1cf79..3f28219 100755 --- a/builder/build +++ b/builder/build @@ -15,6 +15,7 @@ cp -r ../modules ../build cp -r ../locales ../build cp ../manifest.webapp ../build +mkdir -p ../build/scripts/cloud mkdir -p ../build/scripts/lib mkdir -p ../build/scripts/parsers/odt.js/lib cp ../scripts/messages.js ../build/scripts