Http-bind response value

When initiating an http-bind session, I keep getting “not authorized” failures, which I’m sure are caused by an incorrect ‘response’ value being encoded into base64.

I’ve looked at XEP-206: XMPP over BOSH, example 7, but it hasn’t helped.

Are there any examples showing how to correctly calculate the response value, or has anyone here managed to get it working?