How do I log in to Google with my site?

On my site, I want to allow users to log in with a google account. I plan to use openid, but I would like to allow Google login because it has more advantages. In the past, I noticed several sites that have the ability to log in with a google account (gmail) and IIRC, although they did NOT support openID (but I could be wrong).

How to implement "login using google"?

+54
login cross-domain openid gmail google-oauth
06 Oct '09 at 20:30
source share
7 answers

If you plan to use OpenID, use this. Google is already an OpenID 2.0 provider.

The Google OpenID provider is located at: https://www.google.com/accounts/o8/ud

(NOTE: It makes no sense to visit this URI in your browser, but it works for OpenID.)

This is primarily addressed on the Accounts API page, which also covers OAuth and hybrid and proprietary login systems. Depending on your site, you can also use Friend Connect , which is an OpenSocial container that internally uses OpenID for authentication.

Of course, I am biased towards Friend Connect, since I am DPE for this project, but it is probably best for you to contact the OpenID provider directly if you are also not doing something related to the social schedule.

Change for 2012: You want to use OAuth 2.0 to log in . GFC is off .

+29
Oct 06 '09 at 20:49
source share

You might be interested in RPX , which is an all-in-one solution that allows people to choose which identity provider they would like to use to access their site. Not only Google and OpenID are supported, but also many others.

RPX takes care of all the details of interacting with each identity provider and gives you a common API to work with.

+14
Oct. 06 '09 at 21:04
source share

Integrate Google login into your web application

Create a project and client ID for the Google Developers Console .

Download the Google Platform Library

You must include the Google Platforms library in your web pages that integrate Google sign-in.

<script src="https://apis.google.com/js/platform.js" async defer></script> 

Specify the client ID of your application

Enter the client ID that you created for your application in the Google Developers Console with the google-signin-client_id meta element.

 <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com"> 

Note. You can also specify the client ID of the application with the client_id parameter of the gapi.auth2.init () method.

Add Google Login Button

The easiest way to add the Google login button to your site is to use the automatically displayed login button. With just a few lines of code, you can add a button that automatically adjusts to have the appropriate text, logo, and colors for the user's login state and required areas.

To create a Google login button that uses the default settings, add a div element with the g-signin2 class to the login page:

 <div class="g-signin2" data-onsuccess="onSignIn"></div> 

Additional Information. can be found here

+2
Mar 13 '17 at 7:27
source share

I believe you are looking for the Google Accounts API .

+1
Oct 06 '09 at 20:33
source share

I think you want Google Friend Connect

edit: No, you are no more since it is deprecated.

+1
Oct. 06 '09 at 20:35
source share

but i would like to allow google login

In this case, add the following code

HTML

  <div id="mySignin" onclick="login()"><img src="google_image_here.png" alt="google" style="cursor:pointer;height: 60px;width: 309px;"/></div> 

Js

  <script type="text/javascript"> function login() { var myParams = { 'clientid' : 'YOUR_CLIENT_ID.apps.googleusercontent.com', 'cookiepolicy' : 'single_host_origin', 'callback' : 'loginCallback', 'approvalprompt':'force', 'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read' }; gapi.auth.signIn(myParams); } function loginCallback(result) { if(result['status']['signed_in']) { var request = gapi.client.plus.people.get( { 'userId': 'me' }); request.execute(function (resp) { /* console.log(resp); console.log(resp['id']); */ var email = ''; if(resp['emails']) { for(i = 0; i < resp['emails'].length; i++) { if(resp['emails'][i]['type'] == 'account') { email = resp['emails'][i]['value'];//here is required email id } } } var usersname = resp['displayName'];//required name }); } } function onLoadCallback() { gapi.client.setApiKey('YOUR_API_KEY'); gapi.client.load('plus', 'v1',function(){}); } </script> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> 
+1
Jan 29 '16 at 6:20
source share

You can look at openId ( http://openid.net/ ), which is used by SO and maintained by Google.

0
Oct 6 '09 at 20:37
source share



All Articles