Skip to content

Instantly share code, notes, and snippets.

@k0t0vich
Created September 12, 2014 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save k0t0vich/763c4b1f997f603d0c5d to your computer and use it in GitHub Desktop.
Save k0t0vich/763c4b1f997f603d0c5d to your computer and use it in GitHub Desktop.
Social auth for StageWebView
// 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