Skip to content
This repository was archived by the owner on Oct 2, 2018. It is now read-only.

Commit 5e81bcf

Browse files
committed
[OAuth2] Use redirects instead of origin
1 parent 9819961 commit 5e81bcf

File tree

5 files changed

+141
-1
lines changed

5 files changed

+141
-1
lines changed

manifest.webapp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"version": "0.5",
55
"type": "privileged",
66
"launch_path": "/index.html",
7-
"origin": "app://firetext",
87
"developer": {
98
"name": "Airborn OS",
109
"url": "https://www.airbornos.com/"
@@ -94,6 +93,12 @@
9493
"access": "readwrite"
9594
}
9695
},
96+
"redirects": [
97+
{
98+
"from": "https://firetext-server.herokuapp.com/auth/dropbox/oauth2/",
99+
"to": "/modules/oauth2/index.html"
100+
}
101+
],
97102
"activities": {
98103
"open": {
99104
"href": "./index.html",

modules/oauth2/dropbox.svg

Lines changed: 20 additions & 0 deletions
Loading

modules/oauth2/dropbox_oauth2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Launch OAuth Receiver with internal app flag
2+
Dropbox.AuthDriver.FFOSPopup.oauthReceiver(true);

modules/oauth2/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6+
<title>Dropbox Auth</title>
7+
<script src="../../scripts/cloud/dropbox.min.js"></script>
8+
<script src="../../scripts/cloud/dropbox_authdriver_firefoxos_receiver.js"></script>
9+
<script src="dropbox_oauth2.js"></script>
10+
<style>
11+
body, html {
12+
color: #515151;
13+
text-shadow: 0 0 2px white;
14+
background: #ffffff;
15+
font-size: 1em;
16+
}
17+
.container {
18+
text-align: center;
19+
padding: 1rem;
20+
}
21+
h3 {
22+
font-size: 2rem;
23+
font-weight: bold;
24+
font-family: sans-serif;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<div class="container">
30+
<img src="dropbox.svg" alt="Dropbox Logo" width="150" height="150" />
31+
<h3 style="margin: 0;">You can now use Firetext with Dropbox!</h3>
32+
<p><i>This window should close automatically in a few seconds...</i></p>
33+
</div>
34+
</body>
35+
</html>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Firefox OS Popup Dropbox Receiver
3+
* Copyright (C) Codexa Organization.
4+
*/
5+
6+
if (Dropbox && Dropbox.AuthDriver) {
7+
Dropbox.AuthDriver.FFOSPopup = (function(superClass) {
8+
var allowedOrigins = ["https://codexa.github.io", "http://firetext.codexa.bugs3.com", "localhost"];
9+
10+
function FFOSPopup() {
11+
}
12+
13+
FFOSPopup.locationOrigin = function(location) {
14+
var match;
15+
match = /^(file:\/\/[^\?\#]*)/.exec(location);
16+
if (match) {
17+
return "file";
18+
}
19+
20+
match = /^([^\:]+\:\/\/localhost(:[0-9]*){0,1}([\/]|$))/.exec(location);
21+
if (match) {
22+
return "localhost";
23+
}
24+
25+
match = /^([^\:]+\:\/\/[^\/\?\#]*)/.exec(location);
26+
if (match) {
27+
return match[1];
28+
}
29+
return location;
30+
};
31+
32+
FFOSPopup.oauthReceiver = function(inApp) {
33+
window.addEventListener('load', function() {
34+
var frameError, getOriginMessage, ieError, message, opener, pageUrl, receiveMessage;
35+
pageUrl = window.location.href;
36+
getOriginMessage = JSON.stringify({
37+
_dropboxjs_needs_origin: true
38+
});
39+
message = JSON.stringify({
40+
_dropboxjs_oauth_info: pageUrl
41+
});
42+
Dropbox.AuthDriver.BrowserBase.cleanupLocation();
43+
opener = window.opener;
44+
if (window.parent !== window.top) {
45+
opener || (opener = window.parent);
46+
}
47+
if (opener) {
48+
receiveMessage = function(e) {
49+
if (e.source === opener &&
50+
(allowedOrigins.indexOf(Dropbox.AuthDriver.FFOSPopup.locationOrigin(e.origin)) !== -1 ||
51+
inApp)) {
52+
opener.postMessage(message, e.origin);
53+
window.close();
54+
}
55+
};
56+
window.addEventListener('message', receiveMessage, false);
57+
try {
58+
opener.postMessage(getOriginMessage, "*");
59+
} catch (_error) {
60+
ieError = _error;
61+
}
62+
try {
63+
opener.Dropbox.AuthDriver.FFOSPopup.onMessage.dispatch(message);
64+
window.close();
65+
} catch (_error) {
66+
frameError = _error;
67+
}
68+
}
69+
});
70+
};
71+
72+
FFOSPopup.onMessage = new Dropbox.Util.EventSource;
73+
74+
return FFOSPopup;
75+
})(Dropbox.AuthDriver.BrowserBase);
76+
} else {
77+
console.log("Dropbox.js is not present.");
78+
}

0 commit comments

Comments
 (0)