diff --git a/php/callback.html b/php/callback.html new file mode 100644 index 00000000..c79b919a --- /dev/null +++ b/php/callback.html @@ -0,0 +1,10 @@ + + + + Zöff OAuth Callback + + + + + + diff --git a/static/dist/callback.min.js b/static/dist/callback.min.js new file mode 100644 index 00000000..2e9c3b92 --- /dev/null +++ b/static/dist/callback.min.js @@ -0,0 +1 @@ +!function(){function e(e){var t,o=e.substring(1).split("&"),n={};for(var a in o)t=o[a].split("="),2==t.length&&(n[t[0]]=t[1]);return n}window.addEventListener("load",function(){var t,o,n,a=e(window.location.hash),i=window.location.protocol+"//"+window.location.hostname+"/o_callback";if(a.spotify)t="b934ecdd173648f5bcd38738af529d58",o="token",n="playlist-read-private playlist-read-collaborative user-read-private",state=a.nonce,window.location.href="https://accounts.spotify.com/authorize?client_id="+t+"&scope="+n+"&show_dialog=false&response_type="+o+"&redirect_uri="+i+"&state="+state;else if(a.youtube)t="944988770273-butsmlr1aotlsskk8lmgvh0etqqekigf.apps.googleusercontent.com",o="token",n="https://www.googleapis.com/auth/youtube",state=a.nonce,window.location.href="https://accounts.google.com/o/oauth2/v2/auth?client_id="+t+"&response_type="+o+"&state="+state+"&redirect_uri="+i+"&scope="+n;else{var s=e(window.location.hash);window.opener.callback(s)}})}(); \ No newline at end of file diff --git a/static/js/callback.js b/static/js/callback.js new file mode 100644 index 00000000..64556d60 --- /dev/null +++ b/static/js/callback.js @@ -0,0 +1,40 @@ +window.addEventListener("load", function(){ + var query = getQueryHash(window.location.hash); + var redirect = window.location.protocol + "//" + window.location.hostname + "/o_callback"; + var client_id; + var response; + var scope; + + if(query.spotify){ + client_id = "b934ecdd173648f5bcd38738af529d58"; + response = "token"; + scope = "playlist-read-private playlist-read-collaborative user-read-private"; + state = query.nonce; + window.location.href = "https://accounts.spotify.com/authorize?client_id=" + client_id + "&scope=" + scope + "&show_dialog=false&response_type=" + response + "&redirect_uri=" + redirect + "&state=" + state; + + } else if (query.youtube) { + client_id = "944988770273-butsmlr1aotlsskk8lmgvh0etqqekigf.apps.googleusercontent.com"; + response = "token"; + scope = "https://www.googleapis.com/auth/youtube"; + state = query.nonce; + + //window.opener.callback(query); + window.location.href = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + client_id + "&response_type=" + response + "&state=" + state + "&redirect_uri=" + redirect + "&scope=" + scope; + } else { + var query_parameters = getQueryHash(window.location.hash); + window.opener.callback(query_parameters); + } +}); + +function getQueryHash(url){ + var temp_arr = url.substring(1).split("&"); + var done_obj = {}; + var splitted; + for(var i in temp_arr) { + splitted = temp_arr[i].split("="); + if(splitted.length == 2) { + done_obj[splitted[0]] = splitted[1]; + } + } + return done_obj; +}