UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

71 lines (68 loc) 2.02 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Oauth2 callback window</title> <style>*[hidden] { display: none; } </style> </head> <body> <p id="general-error" hidden> The window wasn't opened as a popup and therefore it can't pass authorization information.<br/> This is an error. </p> <script> var $ = function(selector, target) { return (target || document).querySelector(selector); }; var messageTarget = (window.opener || window.top); var Auth = { init: function() { var search = location.search.substr(1); if (search) { Auth.handleResponse(search); } else { Auth.handleResponse(window.location.hash.substr(1)); } }, handleResponse: function(data) { var params = { 'oauth2response': true, 'tokenTime': Date.now() }; data.split('&').forEach(function(p) { var item = p.split('='); var name = item[0]; var origName = name; var i = 0; var l; while ((l = name[i])) { if ((l === '_' || l === '-') && i + 1 < name.length) { name = name.substr(0, i) + name[i + 1].toUpperCase() + name.substr(i + 2); } i++; } params[name] = decodeURIComponent(item[1]); params[origName] = decodeURIComponent(item[1]); }); var origin; try { if ('origin' in messageTarget.location) { origin = messageTarget.location.origin; } } catch (e) { // This will happen when the popup is in different domain // (port, host, scheme) origin = '*'; } messageTarget.postMessage(params, origin); } }; if (!messageTarget || !messageTarget.postMessage) { var elm = $('#general-error'); elm.removeAttribute('hidden'); } else { Auth.init(); } </script> </body> </html>