franmontiel/PersistentCookieJar

Cookies are either not persisting, or not being sent out

Opened this issue · 1 comments

Hi,

We are using this library with OkHttp3 in 2 separate activities.
In the first activity, we are logging in via a POST, and then starting the second activity.
Once there, we request some information to the same server via a GET call (this is a secured endpoint).
This second call is failing saying the request is not authorized.
This system has been on production for years, so we know it's not the issue.

It looks like either the cookies are not being saved on the initial POST response, or sent out on the GET call. I was under the impression they are saved and sent out by this library, is there something extra that needs to be done?

Here's how we're setting up the client (in both activites):

// Have also tried ClearableCookieJar instead of CookieJar
CookieJar cookieJar =
     new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));

OkHttpClient client = new OkHttpClient.Builder()
     .cookieJar(cookieJar)
     .build();

You need to share the OkHttpClient instance between the activities.