![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
net.gotev:cookie-store
Advanced tools
Android InMemory and persistent Cookie Store for HttpURLConnection and OkHttp, with extensions to easily sync cookies in Android WebViews.
Android InMemory and persistent Cookie Store for HttpURLConnection
and OkHttp
, with extensions to easily sync cookies in Android WebViews.
Neither 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.
With this library you have:
Android API 16+
Add this to your dependencies:
implementation "net.gotev:cookie-store:x.y.z"
Replace x.y.z
with
Create your Cookie Manager:
// Example extension function to demonstrate how to create both cookie stores
fun Context.createCookieStore(name: String, persistent: Boolean) = if (persistent) {
SharedPreferencesCookieStore(applicationContext, name)
} else {
InMemoryCookieStore(name)
}
val cookieManager = CookieManager(
createCookieStore(name = "myCookies", persistent = true),
CookiePolicy.ACCEPT_ALL
)
To setup the default Cookie Manager:
CookieManager.setDefault(cookieManager)
Add the following dependency (suitable for JVM and Android):
implementation "net.gotev:cookie-store-okhttp:$cookieStoreVersion"
And when you build your OkHttpClient, set the Cookie Jar:
val okHttpClient = OkHttpClient.Builder()
.cookieJar(JavaNetCookieJar(cookieManager))
.build()
It'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.
You have two ways of doing this:
WebKitSyncCookieManager
java.net.CookieManager
val cookieManager = WebKitSyncCookieManager(
store = createCookieStore(name = "myCookies", persistent = true),
cookiePolicy = CookiePolicy.ACCEPT_ALL,
onWebKitCookieManagerError = { exception ->
// This gets invoked when there's internal webkit cookie manager exceptions
Log.e("COOKIE-STORE", "WebKitSyncCookieManager error", exception)
}
)
Then follow standard instructions from the Usage section to setup HttpURLConnection
or OkHttp
according to your needs.
Incoming Cookies will be automatically synced to WebKit's CookieManager. Syncing is unidirectional from
WebKitSyncCookieManager
toandroid.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.
To clear cookies:
cookieManager.removeAll()
This will clear both the CookieStore
and WebKit's Cookie Manager.
Cookies syncing is entirely up to you and manual.
To copy all cookies from the cookie store to the WebKit Cookie Manager:
cookieManager.cookieStore.syncToWebKitCookieManager()
Remember to do this before loading any URL in your web view.
To remove all cookies from the Cookie Store:
cookieManager.cookieStore.removeAll()
To remove all cookies from WebKit Cookie Manager:
android.webkit.CookieManager.getInstance().removeAll()
That's all folks!
FAQs
Android InMemory and persistent Cookie Store for HttpURLConnection and OkHttp, with extensions to easily sync cookies in Android WebViews.
We found that net.gotev:cookie-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.