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

Cannot call MultiSamlStrategy logout synchronously #394

Closed
ricardosaracino opened this issue Sep 23, 2019 · 3 comments
Closed

Cannot call MultiSamlStrategy logout synchronously #394

ricardosaracino opened this issue Sep 23, 2019 · 3 comments

Comments

@ricardosaracino
Copy link

logout was working when i wasnt using the multi strategy, but my await is not working using the MultiSamlStrategy.prototype.logout

import {MultiSamlStrategy as SamlStrategy} from '../strategies';

@Injectable()
export class SamlPassportLogoutInterceptor implements NestInterceptor {

    private logger = new GlobalLoggerService();

    constructor(@Inject(SamlStrategy) private readonly samlStrategy: SamlStrategy) {
    }

    async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>> {

        const req = context.switchToHttp().getRequest();
        const res = context.switchToHttp().getResponse();

        await (this.samlStrategy as any).logout(req, (error, redirectUrl) => {

            this.logger.debugReq(req, `Saml Redirect ${redirectUrl}`);

            if (error) {
                this.logger.errorReq(req, error);
            } else {
// redirect happens after next.handle
                res.redirect(redirectUrl);
            }
        });

// I hit this first 
        return next.handle();
    }
}
MultiSamlStrategy.prototype.logout = function (req, callback) {
  var self = this;

  this._options.getSamlOptions(req, function (err, samlOptions) {
    if (err) {
      return callback(err);
    }

    self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
    self.constructor.super_.prototype.logout.call(self, req, callback);
  });
};
@stavros-wb
Copy link
Contributor

stavros-wb commented Sep 23, 2019

MultiSamlStrategy needs to call getSamlOptions dynamically, so it will call the callback asynchronously

@ricardosaracino
Copy link
Author

Ok... this is weird and i was a complete fluke that i stumbled on it .. but ...

changing this ...

@Get('logout')
@UseInterceptors(PassportLogoutInterceptor)
@ApiOperation({title: 'Handles the logout'})
public logout() {
}

to this fixed the problem

@Get('logout')
@UseInterceptors(PassportLogoutInterceptor)
@ApiOperation({title: 'Handles the logout'})
public logout(@Req() req, @Res() res) {
}

I wonder if @kamilmysliwiec can chime in on it

@ricardosaracino ricardosaracino changed the title Cannot call MultiSamlStrategy logout synchronously Cannot call MultiSamlStrategy logout synchronously Sep 23, 2019
@ricardosaracino
Copy link
Author

All in all i dont think this is passport-saml problem

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

2 participants