Home / Companies / WorkOS / Blog / Post Details
Content Deep Dive

How to store and refresh session tokens correctly with the WorkOS iOS SDK

Blog post from WorkOS

Post Details
Company
Date Published
Author
Maria Paktiti
Word Count
1,097
Company Posts That Month
89
Language
English
Hacker News Points
-
Post removed?
No
Summary

WorkOS iOS authentication produces a short-lived JWT access token and a refresh token, which should both be stored in the hardware-backed Keychain rather than unencrypted UserDefaults; the access token includes session, user, issuer, organization, role, permission, and expiry information. Refresh tokens rotate with every successful exchange, requiring apps to save the replacement token and discard the prior one, although WorkOS provides a 30-second replay grace period to accommodate concurrent requests or retries. Refresh failures must be classified carefully: a 400 invalid_grant response indicates a terminal session state and requires clearing local credentials and returning the user to sign-in, while network failures, timeouts, rate limits, and server-side 5xx errors are transient and should be retried with backoff without signing the user out. Because the WorkOS iOS SDK leaves session handling to the application, developers must persist updated tokens, distinguish terminal from transient errors, and consult current SDK documentation for exact APIs. Proper sign-out also requires clearing Keychain credentials and ending the corresponding WorkOS session using the access token’s session ID, while dashboard settings allow applications to balance maximum session length, token expiry, inactivity timeouts, refresh traffic, and the speed at which permission changes take effect.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.