简体   繁体   中英

How can I store user info from javascript Google+ login API?

I set up javascript Google+ login on my site following the Google developers setup guide and got it working.

After logging in, it shows a page like this:

User is now signed in to the app using Google+ - plus a disconnect button

User's profile information - My icon, name, tagline, about

User's friends that are visible to this app - a handful of my g+ buddies icons

Authentication logs - access_token, code, scope, id_token, etc

My question is, how can I take that information (a generic ID or their email, I'm assuming), and create a USER record in my database? I was thinking about submitting that ID to my server via AJAX upon successful login, but that seems insecure.

Also, how can I check that this user is logged in on other pages ? I see that if I refresh the page after logging in, the "sign in" button automatically disappears and shows this information instead, so Google knows that this user's logged in. Do I need to add this same javascript on each page? (I hope not)

I'd love to save the user in a session (or a cookie if necessary), so they can log in and use the restricted area, but I'm at a bit of a loss.

I had it working via PHP on my old server, but for my current project, certain limitations mean I can't use the same method.

Thanks in advance

What I ended up doing was sending back the following information:

  • etag

  • id

  • name

  • url

  • image.url

And saved that to my database. Then our site admins can approve the accounts they want. Then when the user comes back to the site and logs in with their Google+ account, it checks our DB using those credentials to find out if it's approved or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM