2

Right now I'm trying to develop a simple website to demo three kinds of logins: Facebook, Google, and Twitter.

I have gotten both Facebook and Twitter to use PHP Sessions to hold user data so I can reference them on any page (such as showing their name, avatar.)

The site I'm making will only use login to store their basic profile information such as id, name, and email simply as a login feature, it is not necessary to use any higher level features.

However, I can't get Google sign-in to dump its contents into a session, Google insists on using a callback and catching the callback through Javascript functions on the page.

Google doc help for this: https://developers.google.com/+/web/signin/add-button

I'm not really familiar with this, and not sure how to reference a user's data page-to-page without writing a bunch of javascript catch functions, and javascript can't set PHP sessions. Plus, I want to make the three somewhat uniform, so whether they are signed into Twitter, Facebook, or Google, I can just write in PHP

if (isset($_SESSION['USERID']))
{show their info no matter what login because they set the same session fields}

And everything would be happy.

So I would like to know if I can just inject Google Login info into PHP sessions and how I'd go about doing that.

============

A trailing question I have is that I've been scouring help and tutorials for Oauth login for days, and have not really arrived at a better understanding of how to do Oauth in the way that I would just understand and write it. It seems way too complicated and specific to each service to write freehand. And most documentation is an ocean of oh god what are they even talking about. So if someone could trigger my understanding in dumb people words that would be great.

2 Answers 2

0

I worked around this problem, my problem and resources in regards to jQuery sign-in can be found here: Google signin callback - get name and email

Reflection on PHP Versus JQuery
Although Google has an API for PHP, when I found it it looked old and deprecated, with little to no help/documentation. Since I was new to Google's specific login flow and I was intent on basic web language solutions (they are rather dedicated to javascript/jQuery) I followed their jQuery sign-in documentation.

Since all my other login options use PHP it was a bother to make so many exceptions for jQuery.
But, what you can do is leave the callback method in the header on your pages. On login, Google verifies the login info and bounces you back to page, you can sweep the user to the right page in the callback, and you can also use AJAX to inject login information into the database.

The good thing about the jQuery signin is you don't have to keep track of PHP sessions and variables. The bad part is it feels a bit ungainly and inconvenient compared to just talking to the server with PHP.

If interested, see workaround link above.

0
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
//DB Insert
$gUser = new Users();
$gUser->checkUser('google',$userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
$_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
var_dump($_SESSION['google_data']);
header("location: account.php");
$_SESSION['token'] = $gClient->getAccessToken();
} else {
$authUrl = $gClient->createAuthUrl();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.