{"id":13609791,"url":"https://github.com/gotev/android-cookie-store","last_synced_at":"2025-04-07T11:11:11.545Z","repository":{"id":36873354,"uuid":"230596646","full_name":"gotev/android-cookie-store","owner":"gotev","description":"Android InMemory and persistent Cookie Store for HttpURLConnection and OkHttp, with extensions to easily sync cookies in Android WebViews.","archived":false,"fork":false,"pushed_at":"2024-06-12T12:55:46.000Z","size":259,"stargazers_count":194,"open_issues_count":6,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T10:07:00.004Z","etag":null,"topics":["android","cookie","httpurlconnection","kotlin","library","okhttp","store","webview"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://paypal.me/alexgt"]}},"created_at":"2019-12-28T10:48:05.000Z","updated_at":"2025-03-23T02:39:03.000Z","dependencies_parsed_at":"2024-08-01T19:43:28.627Z","dependency_job_id":null,"html_url":"https://github.com/gotev/android-cookie-store","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-cookie-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-cookie-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-cookie-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-cookie-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotev","download_url":"https://codeload.github.com/gotev/android-cookie-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640465,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cookie","httpurlconnection","kotlin","library","okhttp","store","webview"],"created_at":"2024-08-01T19:01:38.093Z","updated_at":"2025-04-07T11:11:11.527Z","avatar_url":"https://github.com/gotev.png","language":"Kotlin","readme":"# Android Cookie Store\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Cookie%20Store-green.svg?style=flat)](https://android-arsenal.com/details/1/8000) [![Android Weekly](https://img.shields.io/badge/Android%20Weekly-394-green)](https://androidweekly.net/issues/issue-394) [![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/) ![Maven Central](https://img.shields.io/maven-central/v/net.gotev/cookie-store) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n#### [Latest version Release Notes and Demo App](https://github.com/gotev/android-cookie-store/releases/latest) | [Demo App Sources](https://github.com/gotev/android-cookie-store/tree/master/example/app/src/main/java/net/gotev/cookiestoredemo)\n\nAndroid InMemory and persistent Cookie Store for `HttpURLConnection` and `OkHttp`, with extensions to easily sync cookies in Android WebViews.\n\n## Why?\nNeither `HttpURLConnection` nor `OkHttp` provides a native and rapid way of storing cookies persistently on Android. This library aims to fill this gap, by implementing the standard `java.net.InMemoryCookieStore` in Kotlin, with extendability in mind.\n\nWith this library you have:\n- super tiny footprint (the library is only a bunch of classes)\n- an in memory only cookie store\n- a shared preferences backed cookie store which can survive app reboots\n- possibility to extend both to provide your own custom implementation which best fits your needs without reinventing the wheel for cookie management\n\n## Compatibility\nAndroid API 16+\n\n## Getting started\nAdd this to your dependencies:\n\n```groovy\nimplementation \"net.gotev:cookie-store:x.y.z\"\n```\nReplace `x.y.z` with ![Maven Central](https://img.shields.io/maven-central/v/net.gotev/cookie-store)\n\n## Usage\nCreate your Cookie Manager:\n\n```kotlin\n// Example extension function to demonstrate how to create both cookie stores\nfun Context.createCookieStore(name: String, persistent: Boolean) = if (persistent) {\n    SharedPreferencesCookieStore(applicationContext, name)\n} else {\n    InMemoryCookieStore(name)\n}\n\nval cookieManager = CookieManager(\n    createCookieStore(name = \"myCookies\", persistent = true),\n    CookiePolicy.ACCEPT_ALL\n)\n```\n\n### HttpURLConnection\nTo setup the default Cookie Manager:\n\n```kotlin\nCookieManager.setDefault(cookieManager)\n```\n\n### OkHttp\nAdd the following dependency (suitable for JVM and Android):\n\n```groovy\nimplementation \"net.gotev:cookie-store-okhttp:$cookieStoreVersion\"\n```\n\nAnd when you build your OkHttpClient, set the Cookie Jar:\n\n```kotlin\nval okHttpClient = OkHttpClient.Builder()\n    .cookieJar(JavaNetCookieJar(cookieManager))\n    .build()\n```\n\n### WebView\nIt's a common thing to obtain a cookie from an API and to open an authenticated web page inside an app which needs the cookie. You can find a complete working example in the demo app.\n\nYou have two ways of doing this:\n- Using `WebKitSyncCookieManager`\n- Using standard `java.net.CookieManager`\n\n#### Using WebKitSyncCookieManager\n```kotlin\nval cookieManager = WebKitSyncCookieManager(\n    store = createCookieStore(name = \"myCookies\", persistent = true),\n    cookiePolicy = CookiePolicy.ACCEPT_ALL,\n    onWebKitCookieManagerError = { exception -\u003e\n        // This gets invoked when there's internal webkit cookie manager exceptions\n        Log.e(\"COOKIE-STORE\", \"WebKitSyncCookieManager error\", exception)\n    }\n)\n```\nThen follow standard instructions from the Usage section to setup `HttpURLConnection` or `OkHttp` according to your needs.\n\n\u003e Incoming Cookies will be automatically synced to WebKit's CookieManager. Syncing is unidirectional from `WebKitSyncCookieManager` to `android.webkit.CookieManager` to have a single source of truth and to prevent attacks coming from URLs loaded in WebViews. If you need bi-directional sync, think twice before doing it.\n\nTo clear cookies:\n\n```kotlin\ncookieManager.removeAll()\n```\n\nThis will clear both the `CookieStore` and WebKit's Cookie Manager.\n\n#### Using standard java.net.CookieManager\nCookies syncing is entirely up to you and manual.\n\nTo copy all cookies from the cookie store to the WebKit Cookie Manager:\n```kotlin\ncookieManager.cookieStore.syncToWebKitCookieManager()\n```\nRemember to do this before loading any URL in your web view.\n\nTo remove all cookies from the Cookie Store:\n```kotlin\ncookieManager.cookieStore.removeAll()\n```\n\nTo remove all cookies from WebKit Cookie Manager:\n```kotlin\nandroid.webkit.CookieManager.getInstance().removeAll()\n```\n\nThat's all folks!\n","funding_links":["https://paypal.me/alexgt"],"categories":["Kotlin"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotev%2Fandroid-cookie-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotev%2Fandroid-cookie-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotev%2Fandroid-cookie-store/lists"}