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

Prompt option is being ignored in nodejs when extending PassportStrategy #1011

Open
Sofiosko opened this issue Nov 22, 2023 · 0 comments
Open

Comments

@Sofiosko
Copy link

Tried every possible combination found on forum, but it seems like its ignored completely.

Node version: 16.20

@nestjs/passport: ^10.0.2

passport-google-oauth2: ^0.2.0

import {Injectable} from '@nestjs/common';
import {ConfigService} from '@nestjs/config';
import {PassportStrategy} from '@nestjs/passport';

import {Strategy, VerifyCallback} from 'passport-google-oauth2';
import {GoogleProfile} from "./dto/auth-profile";

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
    constructor(
        protected configService: ConfigService,
    ) {
        super({
            clientID: configService.get('GOOGLE_CLIENT_ID'),
            clientSecret: configService.get('GOOGLE_SECRET'),
            callbackURL: configService.get('GOOGLE_CALLBACK_URL'),
            scope: ['profile', 'email'],
            accessType: 'offline',
            prompt: 'select_account consent',
            approvalPrompt: 'force',
            authorizationURLParameters: {
                prompt: 'select_account consent',
                approvalPrompt: 'force',
            },
        });
    }

    async validate(
        _accessToken: string,
        _refreshToken: string,
        profile: any,
        done: VerifyCallback,
    ): Promise<any> {
        const {id, name, emails, photos} = profile;

        const user: GoogleProfile = {
            provider: 'google',
            providerId: id,
            email: emails[0].value,
            firstName: name.givenName,
            lastName: name.familyName,
            picture: photos[0].value,
        };

        done(null, user);
    }
}
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

1 participant