im trying to use ASWebAuthenticationSession to authenticate with a private identity provider.
- Authentication with ASWebAuthenticationSession starts
- Callback with my custom scheme got called
- I need all Cookies of this requests to authenticate the User within my WKWebView. The callback only sends me the url of my custom scheme and not the request.
I can't transfer the Cookies within the url of my custom scheme because i reach the maximum length of url.
ASWebAuthenticationSession doesn't use HTTPCookieStorage to store the Cookies while the authentication?!
session = ASWebAuthenticationSession(url: urlToCall, callbackURLScheme: scheme)
{ callbackURL, error in
let cookie = callbackURL?.absoluteString.split(separator: "=")[1]
print("Session is \(cookie)")
//How to get Cookies here?
}
Does anyone have solutions?
I run into the same problem, and unfortunately there is no way to get your cookies using
ASWebAuthenticationSession
My solution was to use
WKWebView
for authentication rather thanASWebAuthenticationSession
.This will give you flexibility to achieve what you need mainly because you'll be able to access cookies from you
WebView
.The main difference is that you will need to dismiss the WebView manually, and for this I would say we have to options:
origin or callback url
to your auth provider you will receive it in you scene delegate, and from there reach the code where you are presenting your WebView and dismiss it.WKNavigationDelegate
, and check the redirect URL until it matches the final redirect in your auth process and dismiss the web view from there, this can be done in:Finally to access the cookies
WKWebView
has it's own cookie storage so you probably don't need to do anything else and should be able to open a newWKWebView
and this last one should have the cookies already.Note: To read cookies in your WKWebView you can do do through: