How can you implement token-based authentication in Flask?

Instruction: Describe the steps to implement token-based authentication for a Flask API.

Context: This question examines the candidate's knowledge in securing Flask applications using token-based authentication, a common practice for protecting web APIs.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Choose the token format and lifecycle from the application's trust model. Opaque server-validated tokens and signed JWTs are different options; Flask-JWT-Extended is one library for JWT-based flows, not a replacement for identity verification or authorization.

Issue tokens only after the intended credential/identity checks. For a JWT, use a stable subject, a short explicit expiration and the intended issuer/audience policy...

Related Questions