Appcelerator Titanium Cloud session token expiration limits
0 reputation · 10 Sept 2024, 13:13 UTC
0 reputation · 10 Sept 2024, 13:13 UTC
The Appcelerator Titanium SDK utilizes session tokens via Ti.Cloud.Users.login to authenticate API requests. These tokens have a defined Time-to-Live (TTL), typically 24 hours, after which the server returns a 401 Unauthorized response for subsequent calls.
While the SDK provides the mechanism to obtain these tokens, there is no built-in transparent renewal process. Developers must manually intercept expiration errors and re-invoke the login sequence to maintain session continuity. This creates a design gap regarding how to handle long-running background processes without forcing a full user re-authentication flow.
33275 reputation · 11 Sept 2024, 00:34 UTC
Is there a documented method to extend a session token's validity without the user's original credentials?
No. The Appcelerator Titanium Cloud SDK does not provide a refresh token or a method to extend the 24-hour Time-to-Live (TTL) of a session token. To obtain a new token, the application must re-invoke Ti.Cloud.Users.login using the user's credentials.
What is the recommended architectural pattern for handling 401 responses?
Implement a request wrapper or interceptor for all Cloud API calls. This wrapper should follow this logic:
401 Unauthorized response.Ti.Cloud.Users.login expire exactly 24 hours after issuance.Since the SDK lacks a native refresh mechanism, the industry standard for Titanium apps is to store encrypted credentials locally. This allows the app to maintain session continuity for background processes without interrupting the user experience.
function executeCloudCall(action, params, resolve, reject, isRetry = false) {
Ti.Cloud[action](params, function(response) {
if (response.success) {
resolve(response);
} else if (response.code === 401 && !isRetry) {
// Attempt silent login
Ti.Cloud.Users.login({ username: storedUser, password: storedPass }, function(loginRes) {
if (loginRes.success) {
executeCloudCall(action, params, resolve, reject, true);
} else {
reject(response);
}
});
} else {
reject(response);
}
});
}
Ti.Cloud calls with this wrapper throughout the application.One critical detail that changes this recommendation is whether you store user credentials. If your security policy prohibits storing passwords locally, the silent re-login step is impossible. In this scenario, you must queue pending requests and prompt the user for credentials before retrying the failed operations.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.