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 configure PassportStrategy per Request #95

Closed
Bnaya opened this issue Jul 12, 2019 · 4 comments
Closed

Add ability to configure PassportStrategy per Request #95

Bnaya opened this issue Jul 12, 2019 · 4 comments

Comments

@Bnaya
Copy link

Bnaya commented Jul 12, 2019

I'm submitting a...


[ ] Regression 
[ ] Bug report
[*] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Unable to configure PassportStrategy per request

I want to be able to set custom PassportStrategy settings per request.

My use-case: The app is deployed on dynamic, multiple domains,
And i want to be able to set the callbackURL for oauth providers by the request.host, protocol, etc.

@Injectable({
  scope: Scope.REQUEST,
})
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor(
    @Inject(REQUEST) private readonly request: import("express").Request,
    private readonly authService: AuthService,
  ) {
    super({
      clientID: 'CLIENT_ID', // <- Replace this with your client id
      clientSecret: 'CLIENT_SECRET', // <- Replace this with your client secret
      callbackURL: `${request.protocol}://${request.host}/auth/google/callback`,
      passReqToCallback: true,
      scope: ['profile'],
    });
  }

This code doesn't work, i get unknown strategy "google",
Because the strategies must be not Scope.REQUEST

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jul 14, 2019

EDIT

See this post: #95 (comment)

@cjancsar
Copy link

cjancsar commented Feb 8, 2020

@kamilmysliwiec why are request scoped providers not compatible?

@spion
Copy link

spion commented Feb 11, 2020

The passport API is based on registering strategies to the (typically) global instance and passing the options when constructing the strategy

passport.use(new MyStrategy(options))

Therefore strategies are unfortunately not designed to have request-dependent options or to be instantiated per request.

You could recreate a new passport and re-register strategies for every single request, however, I don't think that's the intended use of the library.

@kamilmysliwiec
Copy link
Member

@nestjs nestjs locked as resolved and limited conversation to collaborators Feb 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants