I'm trying to enable a google login on my site using oauth 2. I've gotten pretty far but am a bit stuck. I can connect to the google account once logged in but not for new users.

-- Edit --
I seem to have it working, I'll leave this here to document the process for anyone coming after me.

Set up Google Account

Pre-requisites: Google Developer Account

Go to developers.google.com
Open the api console
From the drop down menu in the top left:
Select Create
Give the project a name
Press Create Project

The Project will be created and set to active
Select API Access from the left menu
Click the button marked Create an oauth 2.0 client ID
Give the product a name and logo (whatever you want here)
Select web application
enter your site address
click create client id

You will need to edit settings here once you have enabled the drupal modules, so keep the window open. Also you will need the Client ID and the Client secret when configuring drupal.

Configuring Drupal

Required Modules

Enable

  • oauth_common
  • http_client
  • http_client_oauth
  • connector (connector)
  • oauth2_common (oauthconnector)
  • oauthconnector (oauthconnector)

enabling oauthconnector should enable all required modules

Go to the Structure Menu
http://yoursite.com/admin/structure

Open the Oauth Connector page
http://yoursite.com/admin/structure/oauthconnector

Select Add provider from preset
Pick Google from the dropdown menu
Click Add Provider

This will open the add provider screen
Oauth Consumer Key => Client ID from the api console
Oauth Consumer Secret => Client Secret from the api console
Leave the rest as default
Click Save and Proceed

copy the path set under 'CALLBACK URL'
This will look something like:
oauth/authorized/2/1

Go back to your google api console and set the redirect uri to
http://yoursite.com/[CALLBACK URI]

So something like
http://yoursite.com/oauth/authorized/2/1

You can then go and test the connection at
http://yoursite.com/user

Go to the connections tab and try to link your google account

If you have issues, check
the redirect uri set in the api console against the one in the callback url field, and
your client id
client secret
Then try again

If every thing works then go to the permissions page
Check the Connect with Google permission for all users

Display the Connector block on your login page

So, this is as far as I've gotten, I can connect my account to google, but anonymous users don't have a button allowing them to sign in with google id
I think I'm pretty close, could you give us a bit of advice on how to get the rest of the way. I'll continue to document the process as I get through it.

Thanks

Comments

cromac’s picture

Issue summary: View changes

little more explanation

Frans’s picture

:) as i said... it is pretty simple...

Might be a stupid question, but what dou you think is the hardest part and... how to simplify that step?

cromac’s picture

The hardest part was that there was no documentation, that's why I've posted my process here. There isn't to much i can see to really simplify, given that you have to go off and create all the fb twitter google stuff. Maybe with a few edits we could link to this documentation on the project page?

Also, this should maybe be another issue but when i try to create an account using my google id, i get the following message

Your account is currently pending e-mail verification. You have receveid a email with further instructions. Request a new password to start a new e-mail verification.
The account gets created as oauthconnector..... but it does not log me in

Oh and sure while i'm here where do i get the oauth token for future api requests?

Thanks for help
Cormac

pandaPowder’s picture

I just wanted to say thanks very much for the documentation. I was stuck until I found this. It seems to work pretty well

VincentBlouin’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

You could also say that you need to install "php curl" if you are using the 7.x-3.0 version of Oauth (not oauth connector) . Fortunately in the latest dev version of Oauth an error message prevented me from installing the modules until I had php cURL installed.

StacyW’s picture

To get a login button, you go to Structure/Blocks and add the Connector block. You also have to set permissions to allow anonymous users to connect with Google or whichever service provider you are using.

StacyW’s picture

Issue summary: View changes

resolved my own issue - yay!

elaine.ong’s picture

Hi, I am trying to implement this.
Got all the steps above working.

But it only reaches the page 'Authorization finished' with content 'The application has been authorized '.

But what's next? I am expecting it will automatically register the google user.

Appreciate any help.

d0tcom’s picture

This documentation helped me in the beginning and I would like to thank you!
I would add more to the documentation and suggest using the following patch to map the fields correctly:
https://www.drupal.org/files/issues/fix_map-1503258-13.patch

I also recommend using the following scopes since userinfo will be depreciated soon.
https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me

I still can't get the picture to upload but everything else works great! (Name, email, organization, etc)

chosookfong’s picture

I also have the same issue with elaine.ong

only reaches the page 'Authorization finished' with content 'The application has been authorized ' but what should be the next?

Please help

Shashwat Purav’s picture

This documentation is very helpful. Thank you. :)

Samuran’s picture

Missing consumer key..
I filled in the consumer key and secret, but still missing consumer key