forked from oauth-io/oauth-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.min.js
1 lines (1 loc) · 2.45 KB
/
oauth.min.js
1
(function(){var c={oauthd_url:"https://oauth.io/auth"};c.oauthd_base=a(c.oauthd_url).match(/^.{2,5}:\/\/[^/]+/)[0];var b;(function e(){var f=/[\\#&]oauthio=([^&]*)/.exec(document.location.hash);if(f){document.location.hash="";b=decodeURIComponent(f[1].replace(/\+/g," "))}})();function a(f){if(f[0]==="/"){f=document.location.protocol+"//"+document.location.host+f}else{if(!f.match(/^.{2,5}:\/\//)){f=document.location.protocol+"//"+document.location.host+document.location.pathname+"/"+f}}return f}function d(g){var h;var f;try{h=JSON.parse(g.data)}catch(i){}if(!h||!h.provider){return}if(g.provider&&h.provider.toLowerCase()!==g.provider.toLowerCase()){return}if(h.status==="error"||h.status==="fail"){f=new Error(h.message);f.body=h.data;return g.callback(f)}if(h.status!=="success"||!h.data){f=new Error();f.body=h.data;return g.callback(f)}if(!g.provider){h.data.provider=h.provider}return g.callback(null,h.data)}window.OAuth={initialize:function(f){c.key=f},popup:function(k,m){var h;if(!c.key){return m(new Error("OAuth object must be initialized"))}var f=c.oauthd_url+"/"+k+"?k="+c.key+"&d="+encodeURIComponent(a("/"));var j={width:Math.floor(window.outerWidth*0.8),height:Math.floor(window.outerHeight*0.5)};if(j.height<350){j.height=350}if(j.width<800){j.width=800}j.left=window.screenX+(window.outerWidth-j.width)/2;j.top=window.screenY+(window.outerHeight-j.height)/8;var l="width="+j.width+",height="+j.height;l+=",toolbar=0,scrollbars=1,status=1,resizable=1,location=1,menuBar=0";l+=",left="+j.left+",top="+j.top;var g={provider:k};function i(n){if(n.source!==h||n.origin!==c.oauthd_base){return}g.data=n.data;return d(g)}g.callback=function(o,n){if(window.removeEventListener){window.removeEventListener("message",i,false)}else{if(window.detachEvent){window.detachEvent("onmessage",i)}else{if(document.detachEvent){document.detachEvent("onmessage",i)}}}g.callback=function(){};return m(o,n)};if(window.attachEvent){window.attachEvent("onmessage",i)}else{if(document.attachEvent){document.attachEvent("onmessage",i)}else{if(window.addEventListener){window.addEventListener("message",i,false)}}}setTimeout(function(){g.callback(new Error("Authorization timed out"))},600*1000);h=window.open(f,"Authorization",l);if(h){h.focus()}},redirect:function(g,f){f=encodeURIComponent(a(f));f=c.oauthd_url+"/"+g+"?k="+c.key+"&redirect_uri="+f;document.location.href=f},callback:function(f,g){if(!b){return}if(arguments.length===1){return d({data:b,callback:f})}return d({data:b,provider:f,callback:g})}}})();