WKWebview lost cookie when multiple redirect

Hello, I am try to use WKWebview to handle webpage load. But I have met an authorisation cycle.


Our website have more than one redirect(302).Just like PageA->PageB-PageC->PageA. The PageC need cookies of PageB'response.The cookies of PageB'response seems like right,I can see the right cookies of response. When PageB redirect to PageC the PageC's request header have no the cookie before.


I want to inject cookie, But The delegate of WKWebView can not handle 302 response, So I can not inject cookie in right way?

Are you able to validate that your cookies are making it to WKHTTPCookieStore?


Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

Thanks meaton

I have no opportunity to handle cookies, because The navigationDelegate of response can not be triggered when server 302 redirect happen. Any sugguestion will be appreciate.

When I test scenario's like this I try and look for the navigationAction of the desired request. If I can see the outbound request for the specific page (in this case it sounds like Page C) I either try and cancel the request and build a new one by hand or try and add a new cookie to the store during this time.



Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

The problem is that if i create a new request for Page C,i also don't know the PageB's cookies of the 302 response, and the cookie store maybe do not contain the PageB's cookies what I desired. So I can not inject the right cookie.

Oh. You mentioned:

| The cookies of PageB'response seems like right

|

| The problem is that if i create a new request for Page C,i also don't know the PageB's

| cookies of the 302 response, and the cookie store maybe do not contain the PageB's

| cookies what I desired.


That is why I recommended evaluating the navigationAction on Page C to see if adding a cookie to WKHTTPCookieStore is possible. If you continue to run into issues with this you can open a TSI for further investigation.


Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

I am sorry for describing unclearly, "the cookies of PageB'response seems like right" because I have use Charles tool to watch the response data, and I also can see the right cookie in Mac safrai When I debug my app. I have not found the right cookie in cookie store.

Met exactly the same scenario :(

For example, here is some web client request chain:
  • start from some login request like https://xxxx/sso/login

    • > status code 302, redirect to step 2 url

  • some OAuth2.0 request like https://xxx/oauth2/authorize?response_type=code&redirect_uri=xxx

    • > status code 302 and response cookie(like some request token token_1), redirect to step 3 url

  • some authenticate request like https://xxx/auth

    • > important here, this request will have a cookie like token=token_1

...

While iOS client(use WKWebView) will lost the cookie from the response of step 2.
And I tried all the methods in WKNavigationDelegate to intercept these 302 request. ALL FAILED.

Can anyone help to fix this terrible issue Orz!!!
WKWebview lost cookie when multiple redirect
 
 
Q