CookieConfig
public final class CookieConfig : @unchecked Sendable
Configuration for managing cookies in the application.
CookieConfig provides control over how HTTP cookies are stored, persisted,
and managed across requests in your Journey or DaVinci workflows. It supports
both in-memory storage (for temporary cookies) and persistent storage (for
cookies that should survive app restarts).
Cookie Persistence
By default, cookies are stored in memory only. To persist specific cookies
to Keychain storage, add their names to the persist array:
let cookieConfig = CookieConfig()
cookieConfig.persist = ["iPlanetDirectoryPro", "session_token"]
Only cookies whose names appear in the persist array will be saved to
the Keychain. All other cookies remain in memory only and are cleared when
the app terminates.
Custom Storage Configuration
For multi-user scenarios or apps requiring isolated cookie storage, use the custom account initializer:
// User-specific cookie storage
let userCookieConfig = CookieConfig(account: "user_12345_cookies")
// Another user with separate storage
let adminCookieConfig = CookieConfig(account: "admin_cookies")
Integration with Modules
CookieConfig is typically used with CookieModule in Journey workflows:
let journey = Journey.createJourney { config in
config.module(CookieModule.config) { cookieConfig in
cookieConfig.persist = ["iPlanetDirectoryPro"]
// Cookies will be persisted to default Keychain storage
}
}
Note
This class is marked as @unchecked Sendable because its properties
are mutable but access is coordinated through the Journey module system.
See also
CookieModule for the module that uses this configuration
See also
CustomHTTPCookie for the cookie type used in persistent storage
-
A list of cookie names that should be persisted to secure storage.
Only cookies whose names appear in this array will be saved to the Keychain when received from the server. Cookies not in this list are stored in memory only and will be lost when the app terminates.
Common Cookies to Persist
Authentication cookies that maintain session state across app launches should be added to this array:
cookieConfig.persist = [ "iPlanetDirectoryPro", // ForgeRock/PingAM session cookie "session_token", // Custom session cookie "remember_me" // Persistent login cookie ]Default Behavior
By default, this array is empty (
[]), meaning no cookies are persisted. All cookies are stored in memory only.Important
Only include cookie names that are required for maintaining authentication state. Persisting unnecessary cookies can impact storage size and may have privacy implications.Declaration
Swift
public var persist: [String] -
In-memory storage for cookies that are not persisted.
This actor-based storage manages cookies that should only exist for the current app session. Cookies in this storage are automatically cleared when the app terminates.
The storage is used for:
- Cookies not listed in
persist - Temporary cookies received during authentication flows
Session-only cookies
Note
This property is read-only. The storage is initialized automatically and managed by the
CookieModule.Declaration
Swift
public private(set) var inMemoryStorage: InMemoryCookieStorage { get } - Cookies not listed in
-
Persistent storage for cookies listed in the
persistarray.This storage backend (typically Keychain) maintains cookies across app launches. Only cookies whose names appear in
persistare saved here.Default Storage
By default, uses
KeychainStoragewith:- Account identifier:
"COOKIE_STORAGE" - Encryption: Secured key encryption when available
Custom Storage
You can replace this with custom storage implementations:
cookieConfig.cookieStorage = KeychainStorage<[CustomHTTPCookie]>( account: "my_custom_cookies", encryptor: SecuredKeyEncryptor() ?? NoEncryptor() )See also
CustomHTTPCookiefor the cookie type stored persistentlyDeclaration
Swift
public var cookieStorage: StorageDelegate<[CustomHTTPCookie]> - Account identifier:
-
Initializes a new
CookieConfigwith default Keychain storage.This creates a cookie configuration using:
- Empty
persistarray (no cookies persisted by default) - Default Keychain account identifier (
"COOKIE_STORAGE") - Secured key encryption for persistent storage
- Fresh in-memory storage instance
Example
let cookieConfig = CookieConfig() cookieConfig.persist = ["iPlanetDirectoryPro"] // Use in a Journey module config.module(CookieModule.config) { cookie in cookie.persist = cookieConfig.persist }See also
init(account:)for custom storage accountsDeclaration
Swift
public init() - Empty
-
Initializes a new
CookieConfigwith a custom account identifier for Keychain storage.Use this initializer when you need to isolate cookie storage with a unique identifier. This is particularly useful for:
- Multi-user applications where each user needs separate cookie storage
- Multiple DaVinci workflow instances requiring isolated state
- Testing scenarios requiring clean storage separation
The account identifier serves as the Keychain account attribute, allowing multiple cookie stores to coexist without conflicts.
Example: Multi-User Cookie Storage
// Create cookie config for a specific user let userCookieConfig = CookieConfig(account: "user_12345_cookies") userCookieConfig.persist = ["iPlanetDirectoryPro"] // Use in Journey configuration let journey = Journey.createJourney { config in config.module(CookieModule.config) { cookie in cookie.cookieStorage = userCookieConfig.cookieStorage cookie.persist = userCookieConfig.persist } }Example: Isolated Workflow Storage
// Different workflows with separate cookie storage let loginCookies = CookieConfig(account: "login_flow_cookies") let checkoutCookies = CookieConfig(account: "checkout_flow_cookies")Important
Ensure account identifiers are unique across your app to prevent unintended cookie data sharing between different users or workflow contexts.
See also
init()for the default configurationDeclaration
Swift
public convenience init(account: String)Parameters
accountA unique identifier for this cookie storage instance. This value is used as the Keychain account attribute. Choose a descriptive and unique value to avoid conflicts with other storage instances.
View on GitHub