jaredhanson / passport

Simple, unobtrusive authentication for Node.js.

Home Page:https://www.passportjs.org?utm_source=github&utm_medium=referral&utm_campaign=passport&utm_content=about

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prompt option is being ignored in nodejs when extending PassportStrategy

Sofiosko opened this issue · comments

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);
    }
}