Complete Interview Questions & Answer Bank
50 curated technical interview questions and answers covering authentication fundamentals, JWT mechanics, OAuth 2.0 grant types, OIDC specifications, security vulnerabilities, and production architecture patterns.
Q2: What is a JSON Web Token (JWT) and what are its three structural components?
A JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained format for securely transmitting information between parties as a JSON object.
A JWT consists of three parts separated by dots (.):
- Header: Specifies the token type (
JWT) and signing algorithm (HS256,RS256). - Payload: Contains the claims (statements about an entity, e.g., user ID, roles, expiration time).
- Signature: Cryptographic signature generated by combining the Base64URL-encoded header and payload with a secret or private key.
// Base64URL Encoded JWT String:
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
// Decoded Header:
{
"alg": "HS256",
"typ": "JWT"
}
// Decoded Payload:
{
"sub": "1234567890",
"name": "John Doe",
"iat": 1516239022
}- A JWT consists of three Base64URL encoded strings separated by dots: Header, Payload, and Signature.
- JWT payloads are encoded, not encrypted by default; sensitive raw data must never be placed inside a standard JWT.
Q3: What are the standard JWT Registered Claims and their definitions?
RFC 7519 defines a set of optional, standardized claim keys known as Registered Claims to ensure interoperability across applications:
iss(Issuer): Identifies the principal that issued the JWT.sub(Subject): Identifies the principal that is the subject of the JWT (e.g., User ID).aud(Audience): Identifies the recipients that the JWT is intended for.exp(Expiration Time): Identifies the expiration time on or after which the JWT MUST NOT be accepted.nbf(Not Before): Identifies the time before which the JWT MUST NOT be accepted.iat(Issued At): Identifies the time at which the JWT was issued.jti(JWT ID): Provides a unique identifier for the JWT (used to prevent replay attacks).
- Registered claims are standardized shorthand keys designed for interoperable security checks.
- Always enforce
expvalidation on backend resource servers to limit the exposure window of compromised tokens.
Q4: What is the difference between Symmetric (HS256) and Asymmetric (RS256) JWT signing?
- HS256 (HMAC with SHA-256): Uses a single shared secret key for both signing and verifying the token. Both the Auth Server and Resource Server must share and store the identical secret key securely.
- RS256 (RSA Signature with SHA-256): Uses an asymmetric key pair. The Authorization Server signs the JWT using its Private Key, while external Resource Servers verify the signature using the Authorization Server's public key (fetched via JWKS).
- HS256 requires sharing secret keys between Auth Server and APIs; RS256 requires exposing only public keys.
- RS256 is the industry standard for microservice architectures and third-party API consumers.
Q5: Compare Stateful Session Authentication with Stateless JWT Authentication.
In Stateful Session Authentication, the server generates a random Session ID upon login, stores session state in memory/database (e.g., Redis), and returns the Session ID in an HTTP cookie. On each request, the server looks up the Session ID in the database.
In Stateless JWT Authentication, all user context and permissions are encoded directly inside the signed JWT payload returned to the client. Resource servers validate the token cryptographically without making database lookups.
Server-side Database vs Client-side PayloadInstant (Delete session record) vs Complex (Requires blacklist)Requires Shared Session Store vs Inherently Scalable- Session authentication enables instant server-side revocation but creates database lookup bottlenecks.
- JWT authentication scales effortlessly across microservices but complicates token revocation.
Q6: What are the four core roles defined in the OAuth 2.0 framework (RFC 6749)?
OAuth 2.0 defines four distinct roles to separate token authorization from resource handling:
- Resource Owner: The entity capable of granting access to a protected resource (typically the end user).
- Resource Server: The API server hosting the protected user resources, capable of accepting and responding to protected resource requests using access tokens.
- Client: The application making resource requests on behalf of the Resource Owner with its authorization.
- Authorization Server: The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization.
- OAuth 2.0 strictly decouples the Authorization Server from the Resource Server.
- Clients interact with Resource Servers strictly using access tokens issued by the Authorization Server.
Q8: What are the main OAuth 2.0 Grant Types and when should each be used?
OAuth 2.0 provides several grant types tailored for different application architectures:
- Authorization Code Grant + PKCE: For Single Page Apps (SPAs), Mobile Apps, and Web Applications.
- Client Credentials Grant: For machine-to-machine (M2M) communication without user context.
- RefreshToken Grant: Used by clients to obtain new access tokens when current access tokens expire.
- Resource Owner Password Credentials (Deprecated): Legacy flow where user gives credentials directly to client; strictly disallowed in OAuth 2.1.
- Implicit Grant (Deprecated): Legacy SPA flow that returned tokens in URL fragments; completely removed in OAuth 2.1 in favor of PKCE.
- Authorization Code + PKCE is the universal standard for user-facing applications.
- Client Credentials Grant is intended exclusively for server-to-server daemon processes.
Q9: How does the OAuth 2.0 Client Credentials Grant work for Machine-to-Machine (M2M) communication?
The Client Credentials Grant is used when the client application requests access to resources under its own control, rather than requesting access to a specific user's private data.
Execution Flow:
- The confidential client transmits its
client_idandclient_secretdirectly to the Authorization Server's/tokenendpoint using HTTP Basic Auth or request body parameters (grant_type=client_credentials). - The Authorization Server authenticates the client credentials.
- The Authorization Server issues an Access Token containing application-level scopes.
- The client uses the Access Token to call backend APIs.
POST /oauth/token HTTP/1.1
Host: auth.example.com
Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&scope=read%3Areports%20write%3Alogs- Client Credentials Grant involves no end-user interaction or browser redirects.
- Must be used strictly by confidential backend servers capable of securing client secrets.
Q10: What is OpenID Connect (OIDC) and how does it extend OAuth 2.0?
OpenID Connect (OIDC) is an identity layer built on top of the OAuth 2.0 framework. While OAuth 2.0 handles authorization (granting access keys to resources), OIDC extends it to perform user authentication.
OIDC Additions to OAuth 2.0:
- ID Token: A standardized JWT containing user identity profile attributes (claims like
sub,email,name). - UserInfo Endpoint: A protected API endpoint returning detailed user profile attributes.
- Standardized Scopes: Predefined scopes like
openid,profile,email.
- OIDC = OAuth 2.0 (Authorization) + ID Token (Authentication).
- Always include the
openidscope in authorization requests to trigger OIDC behavior.