0

My app has a route /project/:id which is protected by an auth middleware that uses passport to allow visitors to authenticate with their slack account.

I'd like to use phantomJS to render /project/:id to pdf. I thought the best way to do this would be to create a route /print/:id (same auth middleware) which creates a phantom instance and uses the open method to request /project/:id.

When /print/:id is requested, the browser session is detected as normal, that's fine. But when phantom does the internal request, it's session is not authorised. The best option would appear to be copying the browser session onto the phantom session.

I note that phantom's open method allows a settings parameter, but I have no idea what properties on the request object would need to be passed in to that settings parameter.

I note there's a similar question regarding cookies but there's no clear solution there and if I understand correctly, recreating the cookie might be more appropriate for accessing a third party, when you don't have access to the session itself.

Mr5o1
  • 1,698
  • 1
  • 15
  • 20

1 Answers1

0

I infer from the question that you are the developer of the application and have PhantomJS on the same server as this project.

If that's true, the simplest and very reliable solution would be to check if a request for /project/:id was local plus if useragent is PhantomJS's and disable auth middleware that time.

Vaviloff
  • 16,282
  • 6
  • 48
  • 56