You are building a RESTful API with Express.js that will be consumed by various client applications, including mobile and web. How would you design the authentication and authorization mechanisms to ensure maximum security and flexibility?

  • Implement a single hard-coded API key for all clients
  • Use JWT (JSON Web Tokens) for authentication and fine-grained middleware for authorization
  • Allow anonymous access to all endpoints
  • Rely solely on client-side security mechanisms
To ensure maximum security and flexibility in a RESTful API, you should use JWT for authentication, as it allows for stateless authentication and can be used across different client types. Fine-grained middleware can be used for authorization, controlling access to specific endpoints. The other options are insecure or impractical approaches.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *