passport-google-oauth2
passport-google-oauth2 copied to clipboard
Error 400: invalid_request Missing required parameter: scope
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",
It may be because of the problem of passing the scope:
router.get("'/auth/google'", passport.authenticate('google', { scope: ['profile', 'email'] }));
try this :)
You need to add scope inside new GoogleStrategy
scope: ['profile', 'email'],
You need to add scope inside new GoogleStrategy
scope: ['profile', 'email'],
It's working, Thank you so much.
You need to add scope inside new GoogleStrategy
scope: ['profile', 'email'],
this worked for me, thanks a lot @Saicharan0662 .
I am also facing this error I tried all the solutions provided here, but they did not work.
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 }); }
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?
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);
}
}
@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", }) } }