Chapter 5. Secure API Development
In this chapter, we focus on secure API development by showing how to implement zero trust authorization in OAuth-secured APIs. We first explain how to enable unified API security with JWT access tokens. You then learn how to validate JWT access tokens and how to utilize the token data to implement API authorization logic. We then discuss how to handle access token expiration to ensure end-to-end API reliability. As you have to test your APIs, we also show a productive method for testing zero trust APIs. Finally, we demonstrate the theory with an API code example.
Let’s get started by showing how JWT access tokens can enable you to use the same API security code for all types of clients.
Unified API Security with JWT Access Tokens
Different types of client applications have their own best practices for sending access tokens. You should understand that your API code does not need to deal with all of these variations. The API should only ever need to deal with a single unified type of message credential. An API gateway can manage any client-specific security differences so that APIs receive an access token in a format that enables the best API security. That format is a JSON Web Token (JWT). Figure 5-1 illustrates the architecture.
Figure 5-1. End-to-end access token flow
JWTs have a standardized format defined in the JWT specification (RFC 7519) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access