InterviewVault
Welcome back, Sujit Kumar Mishra
Admin
SK Mishra
Revision Mode
Document technical questions and best-practice answers.
Machine Token vs User Token
In a Spring Boot-based web application:
Question:
What is the difference between a Machine Token and a User Token? Where and why would each be used?
Machine Token
1: Used by applications or services (machines), not by real people.
Example: When one backend service talks to another backend service.
2: It usually has fixed permissions and does not represent a specific user.
User Token
1: Used by real people (users) when they log in.
Example: When a user logs in to your web app and gets a token to use APIs.
2: It carries the user's identity and permissions.
Where and Why?
- Use Machine Token for automated, system-to-system communication (e.g., scheduled jobs, microservices).
- Use User Token for user-driven actions (e.g., accessing their data, performing tasks as themselves).
Easy Way to Remember:
1: Machine Token = Robot/Service
2: User Token = Person/Human
Machine tokens are for machines, user tokens are for people.