Thomas (boggyb) wrote in lj_clients,

Problem with sessiongenerate

(x-posted to boggyb and lj_clients)

I'm having problems with sessiongenerate and the cookie it gives. Basically, I want to be able to log in using the client API and grab a session cookie. I then want to use that cookie elsewhere, in this case specifically for viewing friends-only entries that the user account has access to. The problem I'm getting is while the session cookie appears fine, it's not letting me in.

Code and details

Okay, here's what my code does. It's written in VB 6, but should be understandable if you don't know VB. Sensitive information has been replaced with ****.

First, I use the client interface to grab a session cookie. I know I should use digest auth, but for testing I can't be bothered (it's non-trivial in VB). This code also falls over spectacularly if an error occurs, but that's not the problem.

    Set whr = New WinHttpRequest
    whr.Option(WinHttpRequestOption_UserAgentString) = "LJread/0.1 (private development version, email tnmm20@**** for more details)"
    whr.Open "POST", ""
    whr.Send "mode=sessiongenerate&user=boggyb&password=" & InputBox("boggyb's password")
    sCookie = whr.ResponseText
    sCookie = Left$(sCookie, InStr(InStr(sCookie, vbLf) + 1, sCookie, vbLf) - 1)
    sCookie = Replace(sCookie, vbLf, "=")

sCookie now contains something like ljsession=v1:****//Thanks+for+signing+in+/+LiveJournal+loves+you+a+lot+/+Here+have+a+cookie

So far, so good. Next I try to grab a page with it, with code that looks something like this:

    whr.Open "GET", ""
    whr.SetRequestHeader "Cookie", sCookie

That post is friends-only, and I am on my own friends list. I can see it in my friends page when logged in. What I should get is that post. What I actually get is a 403 Forbidden error.

Doing a bit more digging actually shows that my cookie's not being accepted on public posts. I set my journal options so everyone gets the banner (the "powered by lj" one), and if I go to a public post with that code I get the login boxes on that, showing that the cookie wasn't accepted. It's not NTL's proxy server meddling, as I edited an earlier post and the edit showed up. And Etheral shows that the cookie is actually being sent.

Ideas anyone? Is this a problem on my end, or is sessiongenerate broken?

  • 302: lj_dev

    In the interests of consolidating all LiveJournal development-related discussion, we're going to be closing down this community. The same…

  • Plain text to LJ

    I have an old blog from xanga that's in html/plain text and I want to move it over here. Which client would be the best to do this? I also want to…

  • ljKlient 0.2.0 Preview Release 1

    Today marks another milestone in the development of ljKlient — as the first preview of the 0.2 series is released.  Please go to the project…

  • Post a new comment


    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened