← Microsoft Interview Insights
First thing I did was ask whether libraries were fair game, which felt awkward but turned out to be the right call because the whole point was to do it manually.
Start by clarifying that a JWT consists of three Base64URL-encoded parts separated by dots, and that we only need to decode the header and payload. Then outline a function that splits the token, applies Base64URL decoding (handling padding and character replacements), and parses each part as JSON. Emphasize that this is for decoding only, not signature verification, and discuss trade-offs like error handling and security implications.
Pro tip: Mention that Base64URL uses '-' and '_' instead of '+' and '/', and that padding may be omitted—so you need to add '=' padding before decoding. Also note that you should never trust the decoded payload without verifying the signature, which is a common security pitfall.
Explain that a JWT has three parts: header, payload, and signature, separated by dots. Only the first two are Base64URL-encoded JSON.
Split the token by '.', take the first two parts, and decode each from Base64URL to a UTF-8 string. Handle padding and character replacements.
Parse the decoded strings as JSON objects using the language's JSON parser, with error handling for invalid input.
Return the header and payload as objects (e.g., a dictionary or struct) for further use.
Highlight that this does not verify the signature, so it should only be used for non-security-critical decoding. Mention error handling and edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.