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

Add ability to pass in customParameters #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

csidell-earny
Copy link

@csidell-earny csidell-earny commented Jul 11, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ X ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Custom parameters are not considered, which leads to issues where you're unable to specify provider specific fields mentioned in #57

Issue Number: #57

What is the new behavior?

This takes the variable customParameters and automatically handles appending them to the authenticate call.

Does this PR introduce a breaking change?

[ ] Yes
[ X ] No

This shouldn't break anything as it only operates if the specific customParameters variable is set, and I believe most oauth strategies don't use this.

Looking for guidance if the variable name makes sense for the nest context. I didn't use customParams because I felt like that had a higher likelihood of being used by some strategy.

@Sieabah
Copy link

Sieabah commented Jul 14, 2019

Any suggestions @kamilmysliwiec

@utrolig
Copy link

utrolig commented Sep 24, 2020

I'm juist chiming in here, I don't know if this is the way stuff is supposed to work, but I was able to send customParameters
by using the following code

auth.controller.ts

@UseGuards(GoogleGuard)
@Get('/google/login')
  public async loginWithGoogle(): Promise<void> {
    this._logger.debug('Redirecting user to google login.');
  }

google.guard.ts

import { Injectable, ExecutionContext } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
class _GoogleGuard extends AuthGuard('google') {
  async canActivate(context: ExecutionContext) {
    const result = (await super.canActivate(context)) as boolean;
    const request = context.switchToHttp().getRequest();
    await super.logIn(request);
    return result;
  }
}

export const GoogleGuard = new _GoogleGuard({
  prompt: 'consent',
  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

Successfully merging this pull request may close these issues.

None yet

3 participants