wasAsked.

which authentication mechanism you used, if JWT explain it stepwise.

EY · Role not specified · technical

Published

Year not specified · Authentication & Security

Community answers

Posted by wasAsked editorial collection

Example answer: "We used JWT bearer tokens issued by our identity service (or Entra ID), with short-lived access tokens and refresh tokens." Then explain the steps. Step 1 — Login The user submits credentials over HTTPS. The server verifies the password hash (and MFA if enabled). Step 2 — Token creation The server creates an access token with claims: sub (user ID), name, roles, iss, aud, iat and exp (for example 15 minutes), and signs it with a private key (RS256) or a secret (HS256) stored in Key Vault. It also creates a random refresh token, stores its hash in the database with an expiry (for example 7 days), and returns both. Step 3 — Client storage The Angular or React app keeps the access token in memory; the refresh token is kept in an HttpOnly, Secure cookie (or the app uses a BFF), reducing XSS risk. Step 4 — Calling the API An HTTP interceptor adds Authorization: Bearer <access token> to each API request. Step 5 — Validation on the server ASP.NET Core's JwtBearer middleware verifies the signature, issuer, audience and expiry. If valid, HttpContext.User is populated with the claims. Step 6 — Authorization [Authorize] and policies check roles or permissions; services check ownership of specific records (a user only sees their own data). Step 7 — Expiry and refresh When the API returns 401 because the token expired, the interceptor calls /auth/refresh. The server validates the refresh token, rotates it (issues a new one and invalidates the old one) and returns a new access token. The original request is retried. Step 8 — Logout The server revokes the refresh token and the client clears its tokens. Access tokens expire quickly, so the remaining window is small. Security measures to mention: HTTPS only, strong key management and rotation, small clock skew, no sensitive data in claims, rate limiting on login, account lockout after failed attempts, and logging authentication events without logging tokens.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics