google authentication with Node.js (part 1)

It took exactly 10 hours for me , to make every thing work after authenticating user with google in node js. We are going to learn google authentication with Node.js

There are many tutorials on the internet but the problem is that google change it’s structure frequently and the articles are not talking about the things you have to do in the google console. because this part is for begginers and if you already knows about how to configure google , you can go to read how to configure node js server to contact with google OAuth

senario is this: we make url with credentials that google gave us, then redirect our client to the url, user or client will login or choose the account and after that, google redirect user to callback url we configured in our project.

So , I don’t want to talk more than this , let’s take a look at what are we going to learn in this article:

  1. config google for getting name , family , email and photos
  2. connect our node js application to google authentication module (which is going to be in next article)

Configure google project for accessing OAuth and users

first of all, go to google console and create project:

create project in google

 

after creating project , go to Google API’s library page , search for “people” , click on “Google people API” and click on “Enable”. In this API we can access user datas like name , nickname , email , addresses and…

google people api

 

now click on “create credentials” , we have to connect our node js app to google via this credentials informations.

people api

 

 

on create credentials page it is asking these questions:
Which API are you using?   answer: people API
Where will you be calling the API from? are you connecting this api to node js server application??? choose this part on your own, you know better.  at last, choose “User data”.

Don’t get tired 🙁 , it’s going to be done soon. now we have to create an OAuth 2.0 client ID. I am working on “localhost:3000”, and I am configuring google like below:

configure OAuth 2.0 client ID in google

Authorized redirect URIs is the callback function that google after authorization will redirect you on.

Click on Refresh and now we should set up our OAuth consent screen

I’m tired. Whats going on… why so many configurations 😐 ok stop nagging. This page’s (OAuth consent screen page)  configuration is easy.

Fill the form fields: Application name , Application logo if you have one of course , Support email , Authorized domains , Authorized domains , Application Privacy Policy link.

Do not click on add scope unless you know what the f**k you are going to do, this part is for the data you need google return to you and some of them need permissions from google.

I fill the form like below:

OAuth consent screen

now click on save and return to “Credentials” , like below, you will see a list and click on the pencil icon right beside trash icon to edit and read datas.

Credentials

after clicking on pencil you will see page below:

client id for web application

Ok, It’s done 🙂 , copy the “Client Id , Client secret” to import in our project for contacting google.

now every thing is ready for google authentication with Node.js. check next tutorial for connecting google to node js app.

google authentication with Node.js (part 1)

Leave a Reply

Your email address will not be published. Required fields are marked *