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
Forward Passport's info
#24
Comments
Sometimes we want to know why the authenticate process failed.For example, if the jwt token expired, the error info would be stored in thoughts? |
Some passport strategies require to pass arbitrary arguments to done callback. For example https://github.com/jaredhanson/passport-totp#configure-strategy requires to pass key and period. Or it can be info data for req.authInfo (related to nestjs#24). Now one can return array from Strategy#validate method, like ```ts async validate(payload: JwtPayload) { const user = await this.authService.validateUser(payload); if (!user) { throw new UnauthorizedException(); } return [user, 'some info']; } ```
For now, exception filter can be used to trigger
|
Some passport strategies require to pass arbitrary arguments to done callback. For example https://github.com/jaredhanson/passport-totp#configure-strategy requires to pass key and period. Or it can be info data for req.authInfo (related to nestjs#24). Now one can return array from Strategy#validate method, like ```ts async validate(payload: JwtPayload) { const user = await this.authService.validateUser(payload); if (!user) { throw new UnauthorizedException(); } return [user, 'some info']; } ```
Done #29. Published as 6.1.0 |
Many many thanks for that code snippet @lutvianes - there's really not much help available when googling why basic auth does not work in nest and your code fixed it for me. The only bit that was missing for me was hooking the filter up in my controller: @Get('timeBasic')
@UseGuards(BasicAuthGuard)
@UseFilters(BasicAuthExceptionFilter)
getTimeBasic() {
return this.appService.getTime();
} And a different constructor param for the filter (I think that import { BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core';
@Catch(UnauthorizedException)
export class BasicAuthExceptionFilter extends BaseExceptionFilter<UnauthorizedException> {
constructor(adapterHost: HttpAdapterHost) {
super(adapterHost.httpAdapter);
} |
When using
passport-http
to provide someBasic
authentication, I don't receive the Realm in the failure response and therefore I'm not prompted by the browser.It is setting the realm as the failure reason. Because we ignore the
info
argument then it's never sent back to the client.Any idea on how you'd see this working? I'm happy to do the PR.
The text was updated successfully, but these errors were encountered: