ACS sandbox authentication returns generic 401 without indicating token status
0 reputation · 22 May 2025, 03:29 UTC
0 reputation · 22 May 2025, 03:29 UTC
Goal: assess whether the Titanium SDK should automatically renew ACS sandbox tokens when a protected method call returns a 401 error during development testing.
Constraints: the SDK presently does not differentiate between a missing sandbox token and an expired token; it surfaces a generic Ti.Network.HTTPClient 401 error, leaving developers to implement manual token‑refresh logic in test suites. This behavior is not documented as intentional, and the CLI’s --env=dev flag merges development and production ACS blocks, raising uncertainty about whether automatic refresh is expected or a gap that needs clarification.
Questions: Should the SDK automatically attempt to refresh a sandbox token on receiving a 401 from ACS? If so, what conditions should trigger the refresh and how should failures be reported to the developer?
35275 reputation · 22 May 2025, 08:36 UTC
No. The Titanium SDK should not automatically refresh an ACS sandbox token on a generic 401 today. With the current behavior, a 401 from ACS sandbox is indistinguishable from a missing or invalid token versus an expired token, and automatic retry risks infinite loops and masking configuration errors.
ACS sandbox returns a generic HTTP 401 without a reliable, SDK-parsable signal for token expiry. Because the response lacks a consistent error code or WWW-Authenticate reason that the SDK can safely interpret, automatic refresh cannot be gated reliably. The merge of env blocks adds uncertainty about which token is being used, making a 401 ambiguous.
Does the 401 response body contain any structured error code or does the WWW-Authenticate header provide an expiry reason? If a stable, documented signal exists, the recommendation for automatic refresh changes. If the body is empty and headers are generic, automatic refresh should remain disabled.
Use comments to ask for clarification. Post a solution as an answer.
6,610 reputation · 22 May 2025, 10:41 UTC
For ACS sandbox, the token is a JWT with an exp claim. Inspecting exp client-side before a protected call gives a deterministic signal that does not depend on parsing the 401 response.
That check can avoid a round-trip that would otherwise surface as a generic Ti.Network.HTTPClient 401, since the SDK does not surface WWW-Authenticate details.
Note the header format and token lifetime can differ between sandbox and production, and revocation or misconfiguration also returns 401, so any automatic refresh should be gated to known expiry only and remain manual until a stable, documented signal is confirmed.