3

Using NSHTTPCookieStorage i want to read and set the global cookies also used by Safari for an Associated Domain linked with the app

However the docu on Associated Domains is quite sparse and i found only docu for the shared credentials https://developer.apple.com/documentation/security/shared_web_credentials

webcredentials:mydomain.com

what i would need is smth like

cookies:mydomain.com

so how to manage cookies for an Associated Domain?

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
  • Related question: https://stackoverflow.com/questions/532117/can-an-iphone-xcode-application-read-cookies-previously-stored-by-safari-mobile – kelin Dec 16 '17 at 11:27

2 Answers2

1

I don't believe this to be possible using the current API.

Indeed, Radars exist that request this functionality exactly.

From what I've seen in iOS 11, when an application has a domain association and attempts to open an SFSafariViewController instance, the system asks the user for permission, which if granted, passes the cookies of the domain to the Safari view controller instance. (In iOS 10, Safari view controller shares all cookies with Safari.) This method is used in Facebook and Google apps, among others—they present the Safari view controller to obtain a session token, which they use for subsequent network access.

Edit: It seems the functionality described above is handled by SFAuthenticationSession. The system prompts the user to allow data sharing, and a Safari view controller is presented with the URL provided. You also provide a URL scheme, which the opened URL must call with the SSO token.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • 1
    but how do you retrive cookies from SFSafariViewController? are they then available in the NSHTTPCookieStorage from the app? – Peter Lapisu Jan 07 '18 at 14:26
  • @PeterLapisu See my edit. It seems `SFAuthenticationSession` is what you need. You don’t get access to the cookie itself, but you can pass any data you want using a URL scheme. – Léo Natan Jan 08 '18 at 09:46
0

The documentation says:

Cookies are not shared among applications in iOS.

So there is no way to access cookies from Safari.

To access local app cookies associated with the specific URL use this method:

func cookies(for URL: URL) -> [HTTPCookie]?
kelin
  • 11,323
  • 6
  • 67
  • 104