Thomas (boggyb) wrote,

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?

  • Computer specs

    The first part of the long-overdue computer rebuild posts! Back in May, I finally brought my desktop kicking and screaming into the current…

  • Skyward Sword HD: for SCIENCE!

    One thing I've noticed from playing through Skyward Sword HD is how... underwhelming the skyward strike appears, at least to begin with. It takes a…

  • Random quote

    pleaseremove, setting a work quiz: "No, I'm going to get my wrong answers right"

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.