DEV Community

Cover image for Authentication with Google in NodeJS

Authentication with Google in NodeJS

Uddesh on October 02, 2019

While working on OAuth for a long time. I have finally understood the flow. But a few days back I had no idea how OAuth works and I was very frustr...
Collapse
 
abinhho profile image
abinhho

I got this error (Mar 2020)

400. That’s an error.

Error: invalid_request
Custom scheme URIs are not allowed for 'WEB' client type.

Request Details
response_type=code
redirect_uri=testauth.com:3000
scope=email profile
client_id=xxx-rm7s51vmr320brk5b5mrhopgma0e65o9.apps.googleusercontent.com
Collapse
 
yeoupooh profile image
Thomas Jinwoo Min

Thank you for the helpful article.

I found some trivial errors in getting value from OAuth2Data with latest google_key.json.
Below is the fix.

const CLIENT_ID = OAuth2Data.web.client_id;
const CLIENT_SECRET = OAuth2Data.web.client_secret;
const REDIRECT_URL = OAuth2Data.web.redirect_uris;

Collapse
 
uddeshjain profile image
Uddesh

I glad it helped you. An error could be due to the change in the structure of credentials but I'll take look on it.

Collapse
 
ananayarora profile image
Ananay Arora

Thomas, thanks for the fix! This fix is indeed correct and is necessary for the app to function.

Collapse
 
rizwanalam91 profile image
Rizwan Alam

thanks uddesh,,it helped me,,,thanks man for this...
best part is that it is in very very simple language.
i am developing an app in flutter and backend with node js,,
now could u plz guide me that how i can integrate this with my app.
it is running fine in terminal and browser,,but how i can connect this functionality with my app

Collapse
 
rpatelmt profile image
Ritesh Patel

Hiii.... Uddesh ... This is very useful to me.... and it is successfully working for me... But now i want to get my gmail User Name (first name, last name) and email and profile pic...I have used this "gmail.users.getProfile()"...But this gives me only email addeess and other info..But it does not return my gmail account First name, last Name, profile pic url, i don't know how to do it ... do you have any idea ?

Please help me ..

Thank you

Collapse
 
vaibh36 profile image
vaibh36

I am able to get the data for the fitness api My problem is that i am hitting the same api using an android phone for an app based on react-native.
I am not able to do res.redirect(url) on the mobile device. Please suggest.

Appreciate your support!

Collapse
 
dreambit profile image
dreambit • Edited

It is better not to use google lib, and do it by hands by using google rest api.
No magic and no black box.

Collapse
 
mochramdan profile image
Moh Ramdan

Error authenticating
GaxiosError: invalid_request
at Gaxios. (D:\ramdan\my-project\cms-app\node_modules\gaxios\build\src\gaxios.js:73:27)

sorry, I got this error message, what does mean?

Collapse
 
vinothsm92 profile image
Vinoth • Edited

Hi uddesh,
It's is very easy to understand your example.
But I have few doubts in this.

how to get the logged in user's mail id.

Can you help me in this.

Collapse
 
sauravexodus profile image
Sourav Chandra

Very nice brother!