Created
September 12, 2014 09:08
-
-
Save k0t0vich/763c4b1f997f603d0c5d to your computer and use it in GitHub Desktop.
Social auth for StageWebView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FB | |
ClassPrototype.login = function(callback, error) { | |
if(_mod == "mobile") { | |
var url = "https://www.facebook.com/dialog/oauth?client_id=" + CONFIG.desktop.fb.id + | |
"&redirect_uri=" + window.location.protocol + "//" + window.location.hostname + "/checkfb.html" + | |
"&scope=email" + | |
"&response_type=token"+ | |
"&display=popup"; | |
location.href = url; | |
} else { | |
invoke(function() { | |
FB.login(function(response) { | |
ClassPrototype.auth(response, callback, error); | |
}, { scope: "email" }); | |
}); | |
} | |
} | |
//G+ | |
ClassPrototype.login = function(callback, error) { | |
if(_mod == "mobile") { | |
var url = 'https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/plus.login' | |
+'&response_type=code+token+id_token+gsession' | |
+'&redirect_uri=' + window.location.protocol + "//" + window.location.hostname + "/checkgg.html" | |
+'&cookie_policy=' + window.location.protocol + '//' + CONFIG['cookie-domain'].substr(1) | |
+'&client_id=' + CONFIG.desktop.gg.id; | |
location.href = url; | |
} else { | |
gapi.auth.signIn({ | |
clientid: CONFIG.desktop.gg.id, | |
scope: 'https://www.googleapis.com/auth/plus.login', | |
cookiepolicy: window.location.protocol + '//' + CONFIG['cookie-domain'].substr(1), | |
callback: function (result) { | |
if ( result.code ) { | |
var auth_args = { code: result.code, access_token: result.access_token }; | |
riot.common.call("/fcgi/ggauth.php", auth_args, { | |
success: function() { | |
if( $.cookie('atype') === 'gg' ) { | |
if(callback) callback(); | |
} else { | |
if(error) error(); | |
} | |
}, | |
error: function() { | |
if(error) error(); | |
} | |
}); | |
} else { | |
console.error( "Sign-in state: " + result.error ); | |
if (error) error(); | |
} | |
} | |
}); | |
} | |
} | |
// mm | |
ClassPrototype.login = function(callback, error) { | |
if (_mod=="mobile"){ | |
var url = "https://connect.mail.ru/oauth/authorize?client_id=" + CONFIG.desktop.mm.id + | |
"&response_type=token" + | |
"&display=mobile" + | |
"&redirect_uri=" + window.location.protocol + "//" + window.location.hostname + "/mobile"; | |
location.href = url; | |
} else { | |
invoke(function() { | |
_login = [callback, error]; | |
mailru.connect.login(); | |
}); | |
} | |
} | |
// ОК | |
ClassPrototype.login = function(callback, error) { | |
if (_popup) _popup.close(); | |
_login = [callback, error]; | |
var url = _apiURL + | |
"?client_id=" + CONFIG.desktop.ok.id + | |
"&scope=" + escape("SET STATUS;PUBLISH TO STREAM;VALUABLE ACCESS") + | |
"&response_type=code" + | |
"&redirect_uri=" + window.location.protocol + "//" + window.location.hostname + "/checkok.html"; | |
if (_mod == "mobile"){ | |
url = url+ "&layout=m"; | |
location.href = url; | |
} else { | |
_popup = window.open(url, "oklogin", "menubar=no, location=yes, status=yes, width=800, height=600"); | |
} | |
} | |
// VK | |
ClassPrototype.login = function(callback, error) { | |
if (_mod == "mobile"){ | |
var url =_apiURL + | |
"?client_id=" + CONFIG.desktop.vk.id + | |
//"&scope=SETTINGS" + | |
"&redirect_uri=" + window.location.protocol + "//" + window.location.hostname + "/checkvk.html" + | |
"&display=touch&response_type=token"; | |
location.href = url; | |
} else { | |
invoke(function() { | |
VK.Auth.login(function(response) { | |
ClassPrototype.auth(response, callback, error); | |
}); | |
}); | |
} | |
} | |
//TW | |
ClassPrototype.login = function(callback, error) { | |
if (_popup) _popup.close(); | |
_login = [callback, error]; | |
var url = _popupURL; | |
if (_mod =="mobile") | |
location.href = url; | |
else | |
_popup = window.open(url, "twlogin", "menubar=no, location=yes, status=yes, width=800, height=600"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment