2

I'm trying to access an express.js api done with node.js and passport.js. Some methods just work when req.use is available.

I try to log with facebook and twitter from my client app, and I get plain cookie.

Something like connect.sid=jkbsdkjabdkjasdbjkadnaidiadiasdaoidoa

I recreate the client cookie with this method:

            BasicClientCookie clientCookie = new                BasicClientCookie(Metadata.COOKIE_LOGIN, cookieValue);
    clientCookie.setDomain("www.domain.com");
    clientCookie.setPath("/");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    clientCookie.setExpiryDate(calendar.getTime());
    return clientCookie;

And after that I make Json Requests with this:

    HttpUriRequest request = method.createRequest(uri);
    request.addHeader("Accept", "application/json");
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    DefaultHttpClient client = new DefaultHttpClient(params);
    client.getCookieStore().addCookie(USER_SESSION_COOKIE);
    HttpResponse response = client.execute(request);
    String serializedJson = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
    T fromJson = gsonParser.fromJson(serializedJson, clazz);

I cannot get on express' routes methods the user as usual.

I know that I'm doing something wrong but I don't know what.

Anyone has done a connection betweem an android app and passport.js?

Thank you all!

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86
  • +1 I am trying to connect an android client through a nodejs app using passport and having similar problems. – Brad Cunningham Feb 12 '13 at 20:38
  • I tried it a lot and did a lot of research and the only thing I really realized is that it's best to not to use passport for android client auth (for server-browser side is great!) – Javier Manzano Feb 13 '13 at 12:50
  • What did you end up doing? I don't like the idea of storing oAuth tokens on the mobile device so proxying through the server seemed like a good idea. But I can't get any "cookie" like data back to the client successfully. – Brad Cunningham Feb 13 '13 at 19:04

1 Answers1

0

See this question for a quick insight on how to use OkHttp with a persistent cookie store. Using a HTTP library to access your REST API will make things much easier.

Community
  • 1
  • 1
Jonas Köritz
  • 2,606
  • 21
  • 33