Emvents Inc. wants users to be able to sign up to events with their accounts and they want organizers to be able to manage their events. In order to do that, we need to know who is who. In this milestone we will add users and authentication to our RESTful API.
-
Read the PassportJS Docs: Familiarize yourself with the PassportJS authentication library. The sections titled “Configure” and “Basic & Digest” will be very useful to implement the requirements of this milestone. http://passportjs.org/docs
-
Play with passport and passport-http: Install these two libraries using npm and learn how to create a Basic HTTP username & password authentication layer. https://github.com/jaredhanson/passport-http
-
Requirement: The application should have a User schema.
- Each User document should have the following properties: username, password, email address and full name.
-
The Mongo database should have a new collection for Users.
-
A new endpoint to create a User should be available.
- The endpoint should be POST /users
- It should have tests to make sure it works as expected.
- It should not be possible to create a new user with an email that already exists.
- It should not be possible to create a new user with a username that already exists.
- If should return a 409 (Conflict) error if the username or email already exists.
- Optional: The password should be hashed before it’s stored in the database.
-
Passport and passport-http should be used to authenticate users using username and password.
- Passport-http should be used to implement Basic HTTP authentication
- Session support should be disabled
-
All the endpoints created until this point should require the user to provide authentication credentials (username and password).
- Otherwise, they must return a 401 HTTP error.
- The POST /users endpoint should not require authentication
-
Requirement: Use the "Basic Auth" functionality of Postman to test the authentication flow works correctly.
-
Your application should have tests to make sure the authentication logic is working as expected.
- Make sure to modify the existing tests since they now require credentials to be sent with each request.
-
Optional: Your application should use auth tokens or any other similar mechanism (e.g. OAuth) so that clients don't need to send username and password with every request.
NOTE: Do you want to become a remote software developer? Join our online training program where students from all around the world learn together doing remote pair programming, all while working on open source and freelance projects.