API Gateways for Mobile Applications: Authentication, Payloads, and Versioning
API7.ai
September 16, 2026
A mobile API gateway should absorb server-side policy and compatibility work that cannot be shipped instantly to every installed app: validate access tokens, bound payloads, route supported API versions, and expose consistent failure signals. It must not treat the app as a confidential client, promise connectivity, or hide breaking backend changes behind indefinite transformation.
The core constraint is release lag. Web clients can change with the server; mobile versions may remain active for months. Design the gateway and API contract for overlapping client generations.
Key Takeaways
- Native apps are public OAuth clients and cannot safely hold a universal client secret.
- Use the system browser or another external user-agent and Authorization Code with PKCE.
- Validate token issuer, audience, lifetime, scope, and application authorization; device headers are not identity.
- Optimize payload shape and size for variable networks, but keep caching and compression semantics explicit.
- Version around compatibility promises, observe adoption, and retire old versions through a measured policy.
Separate the Mobile and API Trust Boundaries
sequenceDiagram
participant U as User
participant M as Mobile app
participant B as External browser
participant A as Authorization server
participant G as API gateway
participant S as Mobile backend
U->>M: Start sign-in
M->>B: Authorization request plus PKCE challenge
B->>A: User authentication and consent
A-->>M: Authorization code via registered redirect
M->>A: Code plus PKCE verifier
A-->>M: Access token
M->>G: API request plus access token
G->>G: Validate token and route policy
G->>S: Minimal verified context
S->>S: Authorize user and object
S-->>G: Versioned response
G-->>M: Bounded mobile response
RFC 8252 requires native-app authorization requests to use an external user-agent and requires public native clients and authorization servers to use PKCE. RFC 7636 protects an intercepted authorization code by requiring the verifier known to the initiating app.
Do not embed a shared confidential-client secret in the app. It can be extracted from distributed binaries. Device model, operating-system version, app version, push token, IP address, and attestation result may inform risk policy, but none alone proves the user.
Validate Tokens, Then Authorize the Resource
At the gateway, validate the mechanism selected by the authorization system:
- signature or introspection result;
- exact issuer and intended audience;
- expiration and not-before rules with a documented clock policy;
- required route scopes;
- sender-constrained proof when the ecosystem uses one.
Then pass a minimal verified subject and policy context over an authenticated internal path. The backend must still authorize the specific account, object, and action. A valid token is not universal access.
For APIs called directly by a mobile app, Apache APISIX 3.19.0's openid-connect plugin can operate with bearer_only: true. The field defaults to false: the false path supports an authorization-code/session flow at the gateway, whereas the true path strictly requires a bearer token. Keep the native authorization flow in the app and authorization server; use the gateway route as a resource server rather than embedding a browser session contract in the API.
bearer_only does not by itself validate the token audience. In APISIX 3.19.0, claim_validator.audience.required and claim_validator.audience.match_with_client_id both default to false: the false paths do not require aud or match it to the plugin client_id. If that client ID is the intended resource audience, explicitly set both to true; APISIX then requires aud and rejects a string that differs from the client ID or an array that does not contain it. If the mobile API uses a different audience model, configure and test that exact contract instead of assuming bearer mode supplies it.
Bound Payloads for Uncertain Networks
Mobile clients encounter high latency, limited bandwidth, radio transitions, and interrupted uploads. Use the gateway to enforce coarse limits, but fix payload design in the API:
- paginate collections and return only fields the client needs;
- use conditional requests and validators for unchanged resources;
- compress when the saved bytes justify CPU and latency;
- upload large media directly to a dedicated service with short-lived authorization;
- avoid a “mobile” endpoint that performs an unbounded fan-out to many services;
- return machine-readable errors that distinguish authentication, authorization, validation, overload, and version retirement.
This APISIX 3.19.0 configuration excerpt limits one upload route to 1 MiB. The client-control plugin requires APISIX-Runtime, so verify the target build before using it.
{ "uri": "/mobile/v2/profile/photo", "methods": ["POST"], "plugins": { "client-control": { "max_body_size": 1048576 } }, "upstream": { "type": "roundrobin", "nodes": { "mobile-backend.internal:8080": 1 } } }
For max_body_size, a positive value enforces that byte limit and an oversized body produces HTTP 413; the special value 0 disables this check. The gateway limit is only one layer: the app should preflight media size, and the upload service must independently validate actual type, dimensions, ownership, and storage policy.
Choose a Versioning Contract
Path, media-type, or header versioning can all work. Choose one convention that clients, documentation, analytics, and support tooling can see consistently.
| Approach | Advantage | Risk to manage |
|---|---|---|
Path such as /v2 | Visible in logs, links, and routing | Can encourage large duplicated APIs |
| Media type or header | Keeps resource URI stable | Harder to inspect and cache correctly |
| Capability negotiation | Supports incremental features | Can create an untestable combination matrix |
Prefer additive changes within a supported version. When a breaking change is unavoidable, run old and new contracts concurrently, publish an end-of-support date, measure active client versions, and give clients an actionable upgrade response. A gateway transformation can bridge a narrow migration, but it should not become an undocumented second implementation of the business API.
Never route solely from a caller-supplied app-version header and then treat that value as verified software integrity. It is useful telemetry and routing input after validation, not proof that an official binary sent the request.
Design Offline and Retry Behavior
The app can lose connectivity after the server commits a write but before the response arrives. For state-changing operations:
- let the app create a unique operation key;
- bind the key to the authenticated user and request fingerprint in the service;
- return the stored result when the same operation is repeated;
- expose a status lookup for ambiguous outcomes;
- expire keys only after the offline and retry window is understood.
Do not make the gateway silently retry every POST. RFC 9110 prohibits proxies from automatically retrying non-idempotent requests. Coordinate client, gateway, service, and provider retries so their multiplied attempts remain bounded.
Operate a Deprecation Window
Track active users and traffic by privacy-reviewed app version, API version, platform, route, and outcome. Before retirement:
- confirm that authentication and minimum-version policy do not lock out emergency access;
- test old clients against new identity and certificate rotations;
- provide a stable error code, upgrade URL, and grace policy;
- retain a rollback path for gateway routing;
- remove transformations and routes after the published window rather than maintaining them forever.
Verification Checklist
- Does native sign-in use an external user-agent and PKCE?
- Is any embedded secret incorrectly treated as confidential?
- Does the gateway validate issuer, audience, time, scope, and selected proof mechanism?
- Does the backend still authorize the user and object?
- Are upload and response sizes bounded at every relevant layer?
- Can clients distinguish offline ambiguity from a confirmed failure?
- Are POST retries idempotent and bounded?
- Can old and new API versions be observed, rolled back, and retired deliberately?
FAQ
Should a mobile app authenticate directly at the API gateway?
The app normally obtains a token from an authorization server, then presents it to the gateway acting as a resource server. The gateway validates the token; it should not collect the user's password.
Is an app-version header trustworthy?
No. It is caller-supplied unless a separate verified mechanism binds it to an attested client. Use it for compatibility routing and telemetry with that limitation explicit.
Should every mobile response be compressed?
No. Compression helps sufficiently large compressible content, but costs CPU and may not help small or already compressed media. Measure by payload class and network condition.
Next Steps
Review fine-grained authorization, timeout and retry safety, and gateway caching strategy before defining the mobile compatibility contract.