UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

63 lines (60 loc) 1.84 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Oauth2 callback window</title> <style>*[hidden] { display: none; } </style> </head> <body> <h1>Sending authorization data to the application</h1> <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.parent || 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]); }); messageTarget.postMessage(params, '*'); } }; if (!messageTarget || !messageTarget.postMessage) { var elm = $('#general-error'); elm.removeAttribute('hidden'); console.error('Cannot post message to target window.'); } else { Auth.init(); } </script> </body> </html>