p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 278 forks source link

Cache needs flushing when deleting cookies #340

Open ObscureBug opened 4 years ago

ObscureBug commented 4 years ago

I just started using OAuth2 on MacOS 10.15.4 talking to Slack using the embedded authorisation mechanism. Slack prompts for a workspace, followed by a username/password combination and a cookie is used to bypass this on subsequent attempts. Because it may be desirable to validate multiple connections or change accounts, etc. the cookie may need to be cleared.

Although

let storage = HTTPCookieStorage.shared storage.cookies?.forEach() { storage.deleteCookie($0) }

officially removes the cookie, it usually isn't effective as the cookie appears to be cached, even between between app restarts, in ~/Library/Containers/bundleIdentifier/Data/Library/Cookies/Cookies.binarycookies

I found that

_ = WKWebsiteDataStore.default().httpCookieStore

is the sufficient minimum code to cause the cache to be updated. I couldn't find anything in the Apple documentation to indicate this is anything other than a bug in Apple's code but I don't understand the frameworks sufficiently to be sure.

Hopefully someone can clarify things further, or the information is useful.