Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 400: invalid_request Missing required parameter: scope #76

Open
farman05 opened this issue Feb 9, 2021 · 9 comments
Open

Error 400: invalid_request Missing required parameter: scope #76

farman05 opened this issue Feb 9, 2021 · 9 comments

Comments

@farman05
Copy link

farman05 commented Feb 9, 2021

I am stuck with the Missing required parameter: scope, its work fine on local environment but on production its throwing the said error

I am passing the scope like below

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

And using the google strategy like below

passport.use(
    new GoogleStrategy({
        //options for strategy
        callbackURL: `${baseUrl}/auth/google/redirect`,
        clientID: process.env.PASSPORT_CLIENT_ID,
        clientSecret: process.env.PASSPORT_CLIENTSECRET,
    }, (accessToken, refreshToken, profile, done) => {
        //passport callback
       })

passport google auth version : "@types/passport-google-oauth20": "^2.0.4",

@stat1cprojectx
Copy link

It may be because of the problem of passing the scope:

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

try this :)

@Saicharan0662
Copy link

You need to add scope inside new GoogleStrategy

scope: ['profile', 'email'],

@abhidadhaniya23
Copy link

You need to add scope inside new GoogleStrategy

scope: ['profile', 'email'],

It's working, Thank you so much.

@marveldc08
Copy link

You need to add scope inside new GoogleStrategy

scope: ['profile', 'email'],

this worked for me, thanks a lot @Saicharan0662 .

@abdullah032
Copy link

I am also facing this error I tried all the solutions provided here, but they did not work.

@eybel
Copy link

eybel commented Dec 25, 2023

same here, I had the scope parameter and I still get the same error "Missing required parameter: scope". What could be the reason?

@Injectable() export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { constructor() { super({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: process.env.GOOGLE_CALLBACK_URL, scope: ['email', 'profile'], passReqToCallback: true, // Include request object in callback }); }

@ntkthedev
Copy link

same here, I had the scope parameter and I still get the same error "Missing required parameter: scope". What could be the reason?

@Injectable() export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { constructor() { super({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: process.env.GOOGLE_CALLBACK_URL, scope: ['email', 'profile'], passReqToCallback: true, // Include request object in callback }); }

I have the same issue in nestjs, you know how to solve that?

@eybel
Copy link

eybel commented Mar 8, 2024

same here, I had the scope parameter and I still get the same error "Missing required parameter: scope". What could be the reason?
@Injectable() export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { constructor() { super({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: process.env.GOOGLE_CALLBACK_URL, scope: ['email', 'profile'], passReqToCallback: true, // Include request object in callback }); }

I have the same issue in nestjs, you know how to solve that?

I can't remember exactly how I solved it but I will share the final code that I used. I hope it helps:



import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, Profile, VerifyCallback } from 'passport-google-oauth20';

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor() {
    super({
      clientID: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      callbackURL: process.env.GOOGLE_CALLBACK_URL,
      passReqToCallback: true,
      scope: ['email', 'profile'],
    });
  }

  async validate(
    req: any,
    accessToken: string,
    refreshToken: string,
    profile: Profile,
    done: VerifyCallback,
  ): Promise<any> {
    // Validate or create user based on Google profile
    const userProfile = {
      email: profile._json.email,
      firstname: profile._json.given_name,
      lastname: profile._json.family_name,
      picture: profile._json.picture,
    };

    // You can access the request object using req.user if needed
    return done(null, userProfile);
  }
}

@ntkthedev
Copy link

ntkthedev commented Mar 9, 2024

@eybel Thank for your response. I fixed this error. Declare scope in the guard file (like a middlewares in express) instead of in the strategy file.
@Injectable() export class GoogleOAuthGuard extends AuthGuard("google") { constructor() { super({ scope: ["profile", "email"], accessType: "offline", }) } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants