How to get the session cookie after persona authentication


I read this about using persona with couchbase:

Clients log in by sending a POST request to /dbname/_persona. The request body is a JSON document that contains an assertion property whose value is the signed assertion received from the identity provider. Just as with a _session login, the response sets a session cookie.

How does one get the session cookie that is set after accessing the _persona url?

I am trying to understand this so I can allow the user to skip the persona login if their session is still valid.

The result I get back from the urlConnection using _persona is below but I’m not sure if that helps.
“authentication_handlers”: [
“ok”: true,
“userCtx”: {
“channels”: {},
“name”: ""

I saw some code for Java like that listed below, but when I use a urlConnection for, getCookie returns null. Any ideas?


Some Cookie manipulation code:

HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();

// Set cookies in requests
CookieManager cookieManager = CookieManager.getInstance();
String cookie = cookieManager.getCookie(urlConnection.getURL().toString());
if (cookie != null) {
    urlConnection.setRequestProperty("Cookie", cookie);

// Get cookies from responses and save into the cookie manager
List cookieList = urlConnection.getHeaderFields().get("Set-Cookie");
if (cookieList != null) {
    for (String cookieTemp : cookieList) {
        cookieManager.setCookie(urlConnection.getURL().toString(), cookieTemp);

How does one get the session cookie that is set after accessing the _persona url?

An HTTP server sets cookies by adding a Set-Cookie: header in its response.

I can’t answer the rest of your question, not being familiar with Java’s HTTP API. For best results, ask questions on our mailing list instead of this forum –!forum/mobile-couchbase