troydavisson / PHRETS

PHP client library for interacting with a RETS server to pull real estate listings, photos and other data made available from an MLS system
http://troda.com
MIT License
451 stars 236 forks source link

Unable to login, Cookie issue? #62

Closed raducostea closed 7 years ago

raducostea commented 9 years ago

I am having trouble login in to a rets server and i think is something related to cookies. If i use curl command line using a cookie jar file it works (Important: if i dont use a cookie file its not working)

Here is the debug log from the phrets.

[2015-04-29 02:43:23] PHRETS.DEBUG: Loading Monolog\Logger logger [] [] [2015-04-29 02:43:23] PHRETS.DEBUG: Sending HTTP Request for https://rets.crmls.org/contact/rets/login (Login) {"cookies":true,"debug":true} []

< HTTP/1.1 401 Unauthorized < Server: Apache-Coyote/1.1 < Set-Cookie: JSESSIONID=37C5D5128B409C50F0512630F5576E38; Path=/contact < Set-Cookie: JSESSIONID=37C5D5128B409C50F0512630F5576E38; Path=/contact < MIME-Version: 1.0 < Cache-Control: private < RETS-Version: RETS/1.7.2 < WWW-Authenticate: Digest realm="rets@retsiq.com",qop="auth",nonce="a046d8c8edf907fac4c9075805c9d039", opaque="9885bba5142ce" < Content-Type: text/html;charset=utf-8 < Content-Length: 954 < Date: Wed, 29 Apr 2015 09:43:22 GMT <

< HTTP/1.1 401 Unauthorized < Server: Apache-Coyote/1.1 < Set-Cookie: JSESSIONID=1CAB2481E7B7DCD20C72E5F3CE4380F9; Path=/contact < Set-Cookie: JSESSIONID=1CAB2481E7B7DCD20C72E5F3CE4380F9; Path=/contact < MIME-Version: 1.0 < Cache-Control: private < RETS-Version: RETS/1.7.2

GET /contact/rets/login HTTP/1.1 Authorization: Digest username="USER", realm="rets@retsiq.com", nonce="a046d8c8edf907fac4c9075805c9d039", uri="/contact/rets/login", cnonce="ICAgICAgICAgICAgICAgICAgICAgICAgMzc4OTY0MzQ=", nc=00000001, qop=auth, response="ae40d6c00dfb2779b84325a974eb8ba4", opaque="9885bba5142ce" Accept-Encoding: gzip Host: rets.crmls.org RETS-Version: RETS/1.7.2

Second request

Authorization: Digest username="USER", realm="rets@retsiq.com", nonce="eece9c0ac2820413b7d80e47a1f4789a", uri="/contact/rets/login", cnonce="ICAgICAgICAgICAgICAgICAgICAgICAgMzczNTIzODc=", nc=00000001, qop=auth, response="cd4d49644270dccffec3279472b017a0", opaque="2a7dd40718d3f" User-Agent: curl/7.29.0 Host: rets.crmls.org Accept: / Cookie: JSESSIONID=13DDA9E8A272F02041C23DA2CB14CF66

So you can actually see that the first request is missing the cookie resulting in a 401 error.

mikebronner commented 9 years ago

@raducostea Have you made any progress on this? I am able to log into other MLS' just fine, but CRMLS is always giving me "401 Unauthorized". Any ideas?

raducostea commented 9 years ago

@mikebronner not really, i just gave up and i am using the old version of the rets.

mikebronner commented 9 years ago

I did figure a work-around (really poor though) that works for me so far:

        $rets = new Rets($retsConfig);
        $rets->setLogger($log);

        try {
            $rets->Login();
        } catch (Exception $e) {
            $rets->Login();
        }

To me it looks like a server issue with CRMLS (I've had trouble with their servers in the past). Your note about requiring a second attempt triggered this idea, and it seems to work.

Update: apparently that was a fluke that I could connect. Now it won't let me connect anymore. So frustrating to diagnose when its not consistent.

@troydavisson Do have any thoughts on what might be happening here? I noticed there was a closed issue on this back in 2014 that seemed to fix it for v1.

Also contemplating if this is a Guzzle Issue, as the login result shows successful, yet Guzzle triggers a 401 error. Is there a way to tell Phrets 2 to use CURL instead of guzzle?

joselara commented 9 years ago

I believe they go more into depth about the issue here: https://github.com/guzzle/guzzle/issues/1153 and PR has been submitted for Guzzle 6.1.

ooglek commented 8 years ago

This is still a problem. PHRETS/2.0 requires guzzle 4 or 5, but not 6, explicitly. Even if the fix that is suspected of fixing the problem is resolved in 6.1, Troy would need to update PHRETS/2.0 to support Guzzle 6.x.

@troydavisson Any chance that will happen? Are you actively making changes to PHRETS/2.0?

Thanks @mikebronner for the work-around -- agreed it is hacky, but I suspect that a work-around could be put in place that is more clean, such as doing the login again and checking the response to GetSystemMetadata() before actually believing the exception.

troydavisson commented 8 years ago

I've started a new branch which changes PHRETS 2.x to support Guzzle 6+. Please try out the 2.3.x-dev Composer version and report back with any problems you run into.

ilamp commented 7 years ago

Thank you Troy.

I tried 2.3.x-dev but it didn't help either. I've narrowed it down to a missing cookie. Request is not sending the cookie with the request. It might have something to do with the Cookie jar or perhaps it's not included in the request options. I've worked heavily over the past few months with Guzzle and I've already found a few bugs in it.

Another thing I noticed is that the cookie has a path and it could be that guzzle has a bug which doesn't work properly when a path is supplied for the cookie.

ilamp commented 7 years ago

Another thing I noticed is that the server is sending two "Set-Cookie" headers in the response.

ilamp commented 7 years ago

@troydavisson Yup, it's seems that when doing Digest authentication through Guzzle it does not include the cookie required for some servers.

Aranjedeath commented 7 years ago

Hi those of you with the cookie problem might check this solution. (someone else's post)

https://groups.google.com/forum/#!topic/phrets/fr5A3Klgwys

troydavisson commented 7 years ago

Thank you for that link. I missed that post in the group.

I've pushed a change to the 2.3-dev branch which should fix this (at least temporarily until Guzzle does something different).

troydavisson commented 7 years ago

Version 2.3 has been released and includes some changes which should address this. Please give the latest version a try if able.

anaya-prog commented 11 months ago

I am trying version 2.3 but still getting same issue. Anyone have found solution for this?