9 Add authentication and authorization
This chapter covers
- The difference between authentication and authorization.
- How to add authentication to your web service.
- The impact on your API endpoints when thinking about authorization.
- Different forms of authentication you can use for your web service.
- Using cookies with warp.
- Adding a authorization middleware for your routes.
Part 1 and 2 of the book (chapters 1-8) covered the basics of a web service. Everything you need to know to add routes, a database, external APIs and observe a running application via logs. Part 3 has the intention to do everything necessary to ship a Rust web service to production. The three chapters in this last part will cover authentication and authorization, deployment, and testing.
We need everything we learned so far for chapter 9. Adding authentication basically means adding a registration and user route to the API, add a user table to the database and add user ids to the questions and answers. This means extending the API and migrating the database - things we learned in the previous chapters.