My app uses OAuth when logging in. A user is presented with a web view, once they sign in they are given the required tokens, however a cookie is also set. I am using that cookie when opening an WKWebView
within my app so I can render an authenticated page.
These are not persisted across app restarts however, initially I was storing these on UserDefaults
depending on the application life cycle change
applicationDidBecomeActive
applicationWillEnterForeground
applicationDidEnterBackground
applicationWillTerminate
However I do like the idea of storing anything sensitive in here and would much rather store the cookie on the keychain.
What I cannot understand is how I can serialize it in a way that lets me store it?
When I log out a stored cookie, an example I can see is
<NSHTTPCookie
version:0
name:SOMETHING_SOMETHING
value:a_random_hash
expiresDate:'2020-04-20 18:50:49 +0000'
created:'2019-04-21 18:50:49 +0000'
sessionOnly:FALSE
domain:.domain.tld
partition:none
sameSite:none
path:/
isSecure:TRUE
isHTTPOnly: YES
path:"/" isSecure:TRUE isHTTPOnly: YES>)