How do I implement ‘sign in with google’ on my site?

101,243

Solution 1

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

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

(NOTE: There's no point visiting that URI in your browser, but it does work for OpenID.)

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

I'm of course biased towards Friend Connect, since I'm the DPE for that project, but you're probably better served directly using the OpenID provider unless you're also doing stuff that involves a social graph.

Edit for 2012: You want to use OAuth 2.0 for login. GFC is being shut down.

Solution 2

You may be interested in RPX which is an all-in-one solution that lets people choose which identity provider they would like to use to log in to your site. Not only are Google and OpenID supported, but many others as well.

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

Solution 3

Integrating Google Sign-In into your web app

Create a Google Developers Console project and client ID.

Load the Google Platform Library

You must include the Google Platform Library on your web pages that integrate Google Sign-In.

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

Specify your app's client ID

Specify the client ID you created for your app 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 your app's client ID with the client_id parameter of the gapi.auth2.init() method.

Add a Google Sign-In button

The easiest way to add a Google Sign-In button to your site is to use an automatically rendered sign-in button. With only a few lines of code, you can add a button that automatically configures itself to have the appropriate text, logo, and colors for the sign-in state of the user and the scopes you request.

To create a Google Sign-In button that uses the default settings, add a div element with the class g-signin2 to your sign-in page:

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

Other Info. could be found here


Other Possible Solution is

Using OAuth 2.0 to Access Google APIs

Auth Protocols

OAuth 2.0 Overview

OpenID Connect

OAuth 2.0 for Server-side Web Apps

OAuth 2.0 for JavaScript Web Apps

OAuth 2.0 for Mobile & Desktop Apps

Solution 4

I believe what you're looking for is the Google Accounts API.

Solution 5

I think what you want is Google Friend Connect

edit: No you don't any more as it has been deprecated.

Share:
101,243
Admin
Author by

Admin

Updated on December 24, 2020

Comments

  • Admin
    Admin over 3 years

    On my site I would like to allow users to sign in with a google account. I plan to use openid but I would like to allow signing in with google because it has more benefits. I've noticed in the past a few sites that have the ability to sign in with a google (gmail) account and IIRC though they did NOT support openID (but I could be wrong).

    How do I implement 'sign in with google'?

  • Yousaf
    Yousaf over 14 years
    I've used this and it is very easy to set up with an ASP.Net site. Plus it free!
  • Admin
    Admin over 14 years
    Even tho i marked the other as correct i think i'll go with your solution :) (He just wins it bc originally i wanted to see google specific api)
  • Bob Aman
    Bob Aman over 14 years
    As the guy that wrote the other answer, I'll also agree that RPX is probably the best way to actually implement OpenID for most usages. It has a great user interface, and it's easy to install and use.
  • Daithí
    Daithí over 11 years
    instructions on this page: developers.google.com/accounts/docs/OAuth2 look for 'googles api console' to set up an api key etc
  • Daithí
    Daithí over 11 years
    when you click that link look for 'googles api console' to set up a key etc
  • Michael Laffargue
    Michael Laffargue over 10 years
    If you have more than 2500 users a year you'll have to buy the service.
  • Bob Aman
    Bob Aman over 9 years
    @topher OAuth 2.0 and OpenId Connect.
  • Tino
    Tino about 9 years
    PRX does not work for clients which must not use JavaScript. Instead real OpenID 2.0 works without JavaScript like a charm.
  • Tino
    Tino about 9 years
    Telling somebody to look at openid.net for sign in purpose is like telling somebody who wants something to eat to look at a fishing supply store. It simply does not help. Period.
  • Simon H
    Simon H over 5 years
    Is there a way of doing the basics of google login with direct HTTP requests, i.e. without adding https://apis.google.com/js/platform.js to my page?
  • KhogaEslam
    KhogaEslam over 5 years
    OK, you may have your reasons to do so, what about copying it's content and adding it to your site ?
  • KhogaEslam
    KhogaEslam over 5 years
    also you can have a look at these steps developers.google.com/identity/protocols/OAuth2
  • Sachin HR
    Sachin HR over 5 years
    Can you tell how to pass state parameter along with request?
  • Hello World
    Hello World over 3 years
    Is a private policy page also essential?
  • StefaDesign
    StefaDesign about 3 years
    this comment is outdated unfortunately and needs update :(
  • ingmbk
    ingmbk over 2 years
    how can allow all user to connect to the application because i must add the email in google api console