Skip to content

Latest commit

 

History

History
86 lines (52 loc) · 2.84 KB

README.md

File metadata and controls

86 lines (52 loc) · 2.84 KB

node-auth-api

A simple microservice in Node.js with different functionalities using express with Mocha testing, Istanbul code coverage and JWT Authentication.

Build Status license

OVERVIEW

Public endpoints

Login

Request body should contain an arbitrary username/password pair. Key for username and password are 'username' and 'password' respectively.

  • A mock authentication service which accept any username/Password and returns a signed Json Web Token(JWT, https://jwt.io/) which can be used to validate future requests.
  • The JWT expires in 1 hour.

Protected endpoints

JWT GENERATED IN THE "LOGIN" ENDPOINT IS ATTACHED TO EACH REQUEST. AN INVALID JWT WILL RESULT IN REJECTION OF THE REQUEST.

JSON Patch

Request body should contain a JSON object and a JSON patch object. Key for JSON object and JSON patch object are 'doc' and 'thePatch' respectively.

  • Returns the JSON object after applying the JSON patch object.

Thumbnail creation

Request body should contain a public image URL. Key for the URL is 'uri'.

  • Downloads the image, resize it to 50 x 50 pixel and returns the resulting thumbnail.

INSTALLATION

  • Clone the repository git clone https://github.com/darpanjbora/node-auth-api.git
  • Install all dependecies npm install
  • Start the server npm start

RUN THE APIs

Routes

POST login

http://localhost:3000/login

This generates a JWT which is required to access the protected endpoints. All you need to do is pass a arbitrary pair of username and password in the request body. And it returns a JWT which is valid for next 1 hour.

POST JSON patch

http://localhost:3000/patch

This returns a patched JSON object based on the JSON object doc and the patch JSON object thePatch passed in the request body.

POST thumbnail

http://localhost:3000/thumbnail

This returns a thumbnail (50x50 pixels) of the image uri passed in the request body (public URL of the image needs to be passed).

TEST

# To run the mocha test
npm test

# To generate mocha test report using Istanbul
npm coverage

# To view the test report in browser
npm showcoverage

CONTRIBUTING

Contributions, questions and comments are all welcome and encouraged. For code contributions submit a pull request with unit test.

LICENSE

This project is licensed under the MIT License.

AUTHOR

@darpanjbora - darpanjyoti.bora@gmail.com