Skip to content
New issue

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

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

Already on GitHub? # to your account

HttpOnly Cookies #11

Closed
TsunaDev opened this issue Nov 3, 2018 · 4 comments
Closed

HttpOnly Cookies #11

TsunaDev opened this issue Nov 3, 2018 · 4 comments

Comments

@TsunaDev
Copy link

TsunaDev commented Nov 3, 2018

Hey,
I was wondering if there was a way to get the HttpOnly cookies or is it possible to share the session with a http request ?

@pichillilorenzo
Copy link
Owner

Unfortunately, there is no way to get HttpOnly cookies. In case, you can set cookies that will be used by the WebView using the CookieManager.setCookie method. For example:

await CookieManager.setCookie("https://flutter.io/", "myCookieName", "myCookieValue");

@TsunaDev
Copy link
Author

TsunaDev commented Nov 3, 2018

The fact is that I need to get a token (that's stored as a HttpOnly cookie) on the WebView and use it to request some info on the server.
So the only way is to get the HttpOnly cookie or to be able to share cookies between the WebView and my Http requests but it seems not possible.

@pichillilorenzo
Copy link
Owner

The problem is that WebViews don't give access to HttpOnly cookies.
So, maybe you can try using the dart HttpClient class to get your HttpOnly cookie:

import 'dart:io';
import 'dart:async';

Future main() async {
  String token;

  HttpClient client = new HttpClient();

  client.getUrl(Uri.parse("<HERE_MY_URL>")) // or client.postUrl
    .then((HttpClientRequest request) {
      // Optionally set up headers...
      // Optionally write to the request object...
      // Then call close.
      return request.close();
    })
    .then((HttpClientResponse response) {
      // Process the response.
      List<Cookie> cookies = response.cookies;
      print(cookies);
      // Loop the cookies to search your specific cookie with the token 
      for (var cookie in cookies) {
        if (cookie.name == "<MY_COOKIE_NAME>") {
          token = cookie.value;
          print(token);
          break;
        }
      }
    });
}

In this way you can get your token and then you can use it for your next requests.

Let me know if it works.

@iampato iampato mentioned this issue Mar 7, 2020
@DowsingUK DowsingUK mentioned this issue Apr 29, 2020
This was referenced Jul 6, 2020
plateaukao pushed a commit to plateaukao/flutter_inappwebview that referenced this issue Jul 27, 2020
…lve_the_issue_webview_bottom_bar_is_shown_for_iOS_12.3_and_later_versions

TWECACAPP-637 solve the issue webview bottom bar is shown for iOS 12.3 and later versions
@pawangjain pawangjain mentioned this issue Jan 21, 2021
5 tasks
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants