I'm working to get passport-http
working with my application to make it comply with RESTful
principles.
Right now the default is that the browser prompts the user for a username and password with it's own prompt.
With Node.js and PassportJS is it possible to use my own login form? In the case that a user tries to access a page that they are not authenticated for then I would redirect them to that form. Or is this in itself violating the principles of RESTful
design?
REST defines web services. Services are UI agnostic.
In theory, you should be testing your services with a tool such as fiddler, firebug, postman or something similar.
Your UI choices are completely separate.
If you need someone to be able to authenticate, then you will need to handle the visual presentation of the request to user to authenticate.
If you look at the documentation of passport, they show an example of basic authentication:
In this case, the authenticate will redirect the user to the page defined at the root of the website if successful, else the user will be redirected to a page served at /login.
In either case, the login attempt is a post method that comes from a page served by the webserver.
passportjs docs
This is what you need in your server file to create user and password authentication. you need to include the localStategy, configure passport, and use the serialize and deserialize methods. The below works.
login.jade:
signup.jade:
For REST I would suggest you to use HTTP Basic/Digest authentication with HTTPS and you can use http-auth to implement that:
or you can use it without passport: