Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetched cookies doe not have expires field on Android #70

Open
achen0115 opened this issue Aug 11, 2020 · 4 comments
Open

Fetched cookies doe not have expires field on Android #70

achen0115 opened this issue Aug 11, 2020 · 4 comments

Comments

@achen0115
Copy link

achen0115 commented Aug 11, 2020

RN: 0.63.2
Library version: 3.0.0 (also upgraded to 4.0.1, but it does not work either)

I could fetch cookies successfully on Android, but they do not contain expires field, even I set the expiration when saving the cookie.

e.g.

CookieManager.set(theUrl, {
  "domain": ".somesite.com", 
  "expires": "2030-05-30T12:30:00.00-05:00", 
  "name": "AuthenticationToken", 
  "path": "/", 
  "value": "my_token_value", 
  "version": ""
})

I got the following when I called CookieManager.get(theUrl)

{
  "AuthenticationToken": {
    "httpOnly": false,
    "path": null,
    "value": "my_token_value",
    "secure": false,
    "domain": null,
    "name": "AuthenticationToken"
  }
  ...other cookies
}

PS: Path and domain are not returned correctly either on Android as reported in #67.

@shorsher
Copy link

shorsher commented Dec 4, 2020

Hey @achen0115, curious if you ever solved this issue?

@shorsher
Copy link

shorsher commented Dec 4, 2020

After looking at the Android cookie manager docs (https://developer.android.com/reference/android/webkit/CookieManager), this is actually expected behavior. Internally the cookie manager keeps track of the state (expiration, etc.), but the return value of getCookie() returns "value the cookies as a string, using the format of the 'Cookie' HTTP request header", which does not include expiration, path, httpOnly, etc.

However, internally, it seems that CookieManager manages expiration, etc and those values are passed into WebView appropriately.

@peterlazar1993
Copy link

I dug into this on a newer version(13.2.2), as @shorsher mentions, getCookie does not give the raw cookie, but if you inspect the cookie via the WebView inspector, you can see that the cookie has the right expiry value.

But I did have to set the expiry value with this format explicitly yyyy-MM-dd'T'HH:mm:ss.SSSXXX, came to this conclusion after looking at the native code.

@muhammadarsal
Copy link

@peterlazar1993 @shorsher hey there! :) I observed that react-native-webview sets the cookie expiration to 'Session' and does not regard the expires value passed. I am wondering what good is the internal management of cookie expiration if the webview cannot get the expiration date. Did you ever find a workaround for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants