Pergunta de entrevista da empresa WSO2

First ask to describe any project recently done. Then ask how to secure a RestAPI with my API security understanding.

Resposta da entrevista

Sigiloso

18 de jun. de 2025

To secure an API using JSON Web Tokens (JWTs), the process begins when a client authenticates with a server, which then issues a signed JWT containing user claims and an expiration time. This self-contained token is subsequently sent by the client with every API request in an `Authorization` header. The API server, upon receiving a request, validates the JWT's signature using a secret key or public key to ensure its integrity and authenticity, then decodes the payload to extract user information and permissions without needing a database lookup, thereby making the API stateless and scalable. If the token is valid, unexpired, and the claims grant sufficient authorization, the API processes the request; otherwise, it rejects it, effectively securing access based on cryptographically verified user identity. JWT (JSON Web Token) based API security works by generating a self-contained, digitally signed token upon successful user authentication. This token, containing claims about the user (like ID or roles) and an expiration, is then sent back to the client. For all subsequent API requests, the client includes this JWT in the `Authorization` header. The API server, upon receiving a request, verifies the token's signature using a secret key, ensuring its integrity and authenticity without needing to query a database for session information, thus providing a stateless, scalable, and efficient authorization mechanism.