Skip to content
This repository has been archived by the owner. It is now read-only.

Add OAuth2 receiver #305

Merged
merged 1 commit into from Jun 6, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,76 @@
/*
* 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", "app://firetext", "localhost", "file"];

function FFOSPopup() {
}

FFOSPopup.locationOrigin = function(location) {
var match;
match = /^(file:\/\/[^\?\#]*)/.exec(location);
if (match) {
return "file";
}

match = /^([^\:]+\:\/\/localhost(:[0-9]*){0,1}\/{1})/.exec(location);
if (match) {
return "localhost";
}

match = /^([^\:]+\:\/\/[^\/\?\#]*)/.exec(location);
if (match) {
return match[1];
}
return location;
};

FFOSPopup.oauthReceiver = function() {
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))) {
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.");
}
@@ -3,14 +3,16 @@
<head>
<meta charset="utf-8">
<script src="dropbox.min.js" type="text/javascript"></script>
<script src="dropbox_authdriver_firefoxos_receiver.js" type="text/javascript"></script>
<script type="text/javascript">
Dropbox.AuthDriver.Popup.oauthReceiver();
Dropbox.AuthDriver.FFOSPopup.oauthReceiver();
</script>
<style>
body, html {
color: #515151;
text-shadow: 0 0 2px white;
background: #ffffff;
font-size: 1em;
}
.container {
text-align: center;
@@ -26,7 +28,7 @@
<body>
<div class="container">
<img src="dropbox.svg" alt="Dropbox Logo" width="150" height="150" />
<h3 style="margin: 0;">You have successfully connected Firetext with Dropbox!</h3>
<h3 style="margin: 0;">You can now use Firetext with Dropbox!</h3>
<p><i>This window should close automatically in a few seconds...</i></p>
</div>
</body>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.