Adding authentication

To get authentication on order-api, we will use Passport. Passport is a piece of authentication middleware for Node.js, and is considered one of the most widely used pieces of middleware for this purpose. It is known as flexible and modular. There are a lot of strategies that support authentication using a username and password, Facebook, Twitter, JSON Web Tokens (JWTs), and other methods. For the purpose of this book, we will use JWT.

The first step is to install Passport and JWT:

$ npm install --save passport passport-jwt jsonwebtoken passport-local

Then, we need to install the types:

$ npm install --save-dev @types/jsonwebtoken @types/passport-jwt @types/passport @types/passport-local

Now that we have all of the dependencies ...

Get Hands-On RESTful Web Services with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.