chapter eight

8 Implementing API authentication and authorization

 

This chapter covers

  • Documenting API security with OpenAPI
  • Issuing and validating JSON Web Tokens
  • Integrating with an OpenID Connect provider to add authentication to our APIs
  • Validating access tokens issued by an OpenID Connect provider
  • Creating middleware to authorize access to our APIs
  • Implementing role-based access controls

In February 2023, ethical hacker Eaton Zveare discovered major authentication and authorization vulnerabilities in Toyota’s Global Supplier Preparation Information Management System, an application Toyota employees used to manage their supply chain [1]. Zvere was able to do several things: obtain access tokens without providing a password, impersonate Toyota employees, search the employee directory, assume administrator roles, and access highly sensitive data about Toyota’s supply chain. Fortunately, Zveare is an ethical hacker, and he reported the vulnerabilities instead of exploiting them. In the hands of threat actors, however, vulnerabilities like this are the perfect recipe for a major data breach and can put our whole business at risk.

8.1 Documenting authenticated endpoints with OpenAPI

8.2 Issuing JWTs

8.3 Validating JWTs

8.4 Integrating with an OpenID Connect provider

8.4.1 Logging in users and issuing access tokens with an OIDC provider

8.4.2 Validating access tokens issued by an OIDC provider

8.5 Adding authorization middleware

8.6 Implementing role-based access controls

Summary