I am using following code for users to be able to login using their Google account via Javascript API.
HTML
<a id=gp_login href=javascript:void(0) onclick=javascript:googleAuth()>Login using Google</a>
Javascript
function gPOnLoad(){
// G+ api loaded
document.getElementById('gp_login').style.display = 'block';
}
function googleAuth() {
gapi.auth.signIn({
callback: gPSignInCallback,
clientid: googleKey,
cookiepolicy: single_host_origin,
requestvisibleactions: http://schema.org/AddAction,
scope: https://www.googleapis.com/auth/plus.login email
})
}
function gPSignInCallback(e) {
if (e[status][signed_in]) {
gapi.client.load(plus, v1, function() {
if (e[access_token]) {
getProfile()
} else if (e[error]) {
console.log(There was an error: + e[error])
}
})
} else {
console.log(Sign-in state: + e[error])
}
}
function getProfile() {
var e = gapi.client.plus.people.get({
userId: me
});
e.execute(function(e) {
if (e.error) {
console.log(e.message);
return
} else if (e.id) {
// save profile data
}
})
}(function() {
var e = document.createElement(script);
e.type = text/javascript;
e.async = true;
e.src = https://apis.google.com/js/client:platform.js?onload=gPOnLoad;
var t = document.getElementsByTagName(script)[0];
t.parentNode.insertBefore(e, t)
})()
This code is working fine.
I want to use the above code (using Javascript) to login user from their Google account without triggering a popup window. Like, user clicks the login link, asked for app permissions in the same window/tab, user grants permission, user redirected back to the page where Google login link was, profile data is saved and user is logged in.