Token based authentication in Web API without any user interface
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If there is no user interface, token-based authentication is still normal. The difference is that the client is usually another service, script, daemon, or mobile/backend component, so the design should focus on machine-to-machine authentication rather than browser login screens.
Start with the Real Question: Who Is the Client
Without a UI, the client is usually one of these:
- another backend service
- a scheduled job
- a CLI tool
- a mobile app backend
- an integration partner system
That matters because the right token flow depends on whether you are authenticating:
- a machine
- an end user
- or both
For headless service-to-service communication, the most common pattern is a client-credentials style token flow or a signed service token issued by your identity provider.
A Typical Bearer Token Pattern
The API exposes protected endpoints. The client first obtains a token, then sends it in the Authorization header:
On the server side, the API validates:
- signature
- expiration
- issuer
- audience
- scopes or roles
If validation passes, the request is authorized.
That is token-based authentication whether a browser is involved or not.
Machine-to-Machine Tokens Are Better Than Username and Password
If there is no UI, avoid designing an API around raw username and password submission on every request. A better model is:
- client authenticates once with its own credentials
- identity provider issues a short-lived access token
- API accepts that token on subsequent calls
This improves:
- revocation
- auditability
- least-privilege scoping
- secret rotation
It also decouples the API from hard-coded user-password flows that do not fit service integrations well.
Example Token Validation in an API
A simple Python example with JWT validation might look like this:
In production, many teams validate tokens issued by an external identity provider rather than minting and verifying them entirely inside the same API codebase.
The principle is the same either way: the API trusts a signed token, not a browser session.
Use Scopes or Roles, Not Just Identity
Authentication answers "who is this client?" Authorization answers "what is it allowed to do?"
A good token design includes claims that let the API enforce that distinction:
- service identity
- audience
- scopes
- roles
- expiration
For example, one token may allow read:orders while another allows both reading and writing. That is much safer than one universal long-lived token with unlimited access.
Token Storage Still Matters
No UI does not mean no storage risk. Headless clients still need to protect:
- client secrets
- signing keys
- refresh tokens
- cached access tokens
For a backend service, that usually means:
- secret manager
- environment injection
- short-lived tokens
- no hard-coded secrets in source control
The absence of a login page does not reduce the need for secret hygiene.
When API Keys Are Enough
Not every headless integration needs OAuth-style flows. For simple internal or low-risk scenarios, an API key may be enough. But API keys are weaker than scoped bearer tokens because they are often:
- long-lived
- hard to rotate safely
- coarse in permissions
- harder to audit by principal
So if the integration is serious or long-lived, token-based authentication is usually the better design.
Common Pitfalls
- Designing a headless API around username and password on every request.
- Using one permanent token with broad access instead of short-lived scoped tokens.
- Treating authentication and authorization as the same problem.
- Storing client secrets in source control or container images.
- Assuming "no UI" means security can be simpler than normal.
Summary
- Token-based authentication works perfectly well for APIs with no user interface.
- In headless systems, the client is usually another service or machine, so machine-to-machine token flows are the right model.
- The API should validate token signature, issuer, audience, expiration, and scopes.
- Short-lived scoped tokens are usually better than raw passwords or permanent API keys.
- No UI changes the client type, not the need for strong authentication design.
Related reading
- TOKEN endpoint returns invalid_client without client secret
- Tomcat Web Application Not Loading Correctly in Docker Container HTTP Status 404
- toomanyrequests You have reached your pull rate limit. You may increase the limit by authenticating and upgrading
- Traefik v2.2 Ingress Route example not working
- TortoiseGit save user authentication / credentials
- Traefik Forward Authentication in k8s ingress controller
- Transferring Files between two EC2 Instances in the same region
- Transport security has blocked a cleartext HTTP

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.