Skip to content

Commit

Permalink
Redirect oauth requests based on gecko support
Browse files Browse the repository at this point in the history
  • Loading branch information
arcturus committed Jul 2, 2013
1 parent b0bd143 commit fee5bcb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion importer/js/importer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var googleAuth = 'https://accounts.google.com/o/oauth2/auth?scope=https://www.google.com/m8/feeds/&response_type=token&redirect_uri=http://redirector.cloudfoundry.com/&approval_prompt=force&client_id=206115911344.apps.googleusercontent.com';
var googleAuth = 'https://accounts.google.com/o/oauth2/auth?scope=https://www.google.com/m8/feeds/&response_type=token&redirect_uri=http://redirector.cloudfoundry.com/redirect.html&approval_prompt=force&client_id=206115911344.apps.googleusercontent.com';
var authWindow;

var menu = document.getElementById('importer-menu');
Expand Down
7 changes: 6 additions & 1 deletion importer/manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
"60": "/style/icons/icon.png",
"120": "/style/icons/icon.png",
"128": "/style/icons/icon.png"
}
},
"redirects": [
{"from": "http://redirector.cloudfoundry.com/redirect.html",
"to": "/redirect.html"}
],
"version": "1.0.1"
}
11 changes: 11 additions & 0 deletions importer/redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OAuth Redirection</title>
<script defer src="redirect.js"></script>
</head>
<body>

</body>
</html>
34 changes: 34 additions & 0 deletions importer/redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

var Redirect = function Redirect() {

var ORIGIN = document.location.protocol + '//' +
document.location.host;

var init = function init() {
var hash = document.location.hash.substring(1);
var parameters = {};

var dataStart = hash.indexOf('access_token');

if (dataStart !== -1) {
var elements = hash.split('&');

elements.forEach(function(p) {
var values = p.split('=');
parameters[values[0]] = values[1];
});

window.opener.postMessage(parameters, ORIGIN);
window.close();
}

};

return {
'init': init
};

}();

Redirect.init();

0 comments on commit fee5bcb

Please sign in to comment.