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:
- config google for getting name , family , email and photos
- 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:
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…
now click on “create credentials” , we have to connect our node js app to google via this credentials informations.
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:
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.
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:
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.
after clicking on pencil you will see page below:
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.
- what is pwa
- google authentication with Node.js (part 2)