Handling Cookies in Flutter
Asked Answered
D

1

7

I want to make a new flutter application, I'm using the Facebook Login SDK (for flutter). The login was succefully implemented and I am able to get the accesstoken and the UID of the connected user.

My problem is, when the user logs in, I want to keep these cookies to use it with an HTTP request. I was able to make with native android (with the cookiejar and OKHTTP library). I'm wondering if it is still possible with Flutter.

Daubery answered 1/11, 2018 at 13:2 Comment(2)
Have you tried using the Cookie class?Olla
@SnakeyHips how could I use it to get the webview Cookie ?Daubery
D
-2

Check out requests, a flutter library to help with modern RESTful http requests (basic cookies support and json)

  • as of now, it uses shared_preferences which is not the best practice (security-wise) to store sensitive data (session-ids etc) Issue #1

pubspec.yaml

dependencies:
  requests: ^1.0.0

Usage:

import 'package:requests/requests.dart';

// ...

// this will persist cookies
await Requests.post("https://example.com/api/v1/login", body: {"username":"...", "password":"..."} ); 

// this will re-use the persisted cookies
dynamic data = await Requests.get("https://example.com/api/v1/stuff", json: true); 
Diaz answered 1/2, 2019 at 5:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.