I have 2 applications, both app uses the WKWebview for SSO login. Both apps are working fine individually.
Now let's take this below scenario.
Suppose i logged in one app, retrieved the WKWebview cookie from this app & set this cookie info in WKWebview of 2nd app.My expectation is SSO should work in 2nd app but it isn't working.
Below is the code i am using for Retrieving cookie from WKwebview after login from 1st app
extension WKWebView {
@available(iOS 11.0, *)
private var httpCookieStore: WKHTTPCookieStore {
return WKWebsiteDataStore.default().httpCookieStore
}
func getCookies(for domain: String? = nil, completion: @escaping ([String : Any])->()) {
var cookieDict = [String : AnyObject]() if #available(iOS 11.0, *) {
httpCookieStore.getAllCookies {
(cookies) in for cookie in cookies {
print("cookie iterator started") print("cookie=======\(cookie)")
if let domain = domain {
if cookie.domain.contains(domain) {
cookieDict[cookie.name] = cookie.properties as AnyObject?
}
}else {
cookieDict[cookie.name] = cookie.properties as AnyObject?
}
}
completion(cookieDict)
}
} else { // Fallback on earlier versions
}
}
}Below is the code i am using for setting cookie in WKwebview of 2nd app
let cookie= HTTPCookie(properties: [
.domain: "dev.mycompany.net",
.path: "/",
.name: "PF",
.value: "327y48234g2hgdhjwedguyw23oSYVbVLwf9",
.secure: "TRUE",
.version: 1,
.expires: NSDate(timeIntervalSinceNow: (562225018+1000000)) ])!
HTTPCookieStorage.shared.cookieAcceptPolicy = HTTPCookie.AcceptPolicy.always
HTTPCookieStorage.shared.setCookie(cookie)