0

I am working with OAuth Google API and I am getting the 401 Error: invalid_client. It is nothing to do with clientID or clientSecret code, because I'm sure that I copied the keys perfectly. I created again a new credential to make sure that it is not a problems of the Google API, but the error still exists. I also don't receive any error in the console when I am running the server. Could someone helps me, please?

It is what I receive from the browser:

>      401. That’s an error.
>         
>         Error: invalid_client
>         
>         The OAuth client was not found.
>         
>         Request Details
>         response_type=code
>         redirect_uri=http://localhost:5000/auth/google/callback
>         scope=profile email
>         client_id=keys.googleClientID
>         That’s all we know.

This is part of my code:

 passport.use(
      new GoogleStrategy(
        {
          clientID: 'keys.googleClientID',
          clienSecret: 'keys.googleClientSecret',
          callbackURL: '/auth/google/callback'
        },
        (accessToken, refreshToken, profile, done) => {
          console.log('access token', accessToken);
          console.log('refresh token', refreshToken);
          console.log('profile', profile);
        }
      )
    );

  app.get(
    '/auth/google',
    passport.authenticate('google',{
      scope: ['profile', 'email']
    })
  );
  app.get('/auth/google/callback', passport.authenticate('google'));

Thanks! :)

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
pilar torres
  • 1
  • 1
  • 1
  • invalid_client means that the client id and or secret invalid for the code you are using.(**The OAuth client was not found** google isnt lieing to you) So it defiantly has something to do with the client. If you are sure you copied them correctly and didn't delete them on dev console. What type of client did you create? – Linda Lawton - DaImTo Oct 10 '19 at 13:14
  • Thank you for your answer, but what do you mean with **type of client**? – pilar torres Oct 10 '19 at 14:38
  • I am not a node expect but aren't you send the string keys.googleClientID – Linda Lawton - DaImTo Oct 10 '19 at 15:03

1 Answers1

0

As i mentioned in my comment it looks to me that you are sending 'keys.googleClientID' which is not a valid key you need to send the value of the variable. keys.googleClientID

 passport.use(
      new GoogleStrategy(
        {
          clientID: keys.googleClientID,
          clientSecret: keys.googleClientSecret,
          callbackURL: '/auth/google/callback'
        },
        (accessToken, refreshToken, profile, done) => {
          console.log('access token', accessToken);
          console.log('refresh token', refreshToken);
          console.log('profile', profile);
        }
      )
    );
Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449