Unable to authenticate (401 Error)

369 views
Skip to first unread message

Patrick Howe

unread,
May 25, 2016, 11:33:02 AM5/25/16
to PHRETS
Hi,

I am failing to connect to a rets server that is using digest authentication. First off i will say that this is working fine on retsmd.com and using the RETS Connector client application, however when i use phrets its giving me the following error:


Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] http://matrixrets.alamls.net/rets/login.ashx [status code] 401 [reason phrase] Access Denied' in C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:89 Stack trace: #0 C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\Subscriber\HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\Event\Emitter.php(109): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction)) #4 C:\wamp\www\rets\vendor\react\promise\src\FulfilledPromise.php(25): GuzzleHttp in C:\wamp\www\rets\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 89

Now i know that you guys have suggested in other threads with this error to try setting the cookies, however i have already done so. The thing i will say about this is that i am running a windows OS with a wamp server that i test my code on before pushing to my production server which is on linux. The reason why i bring this up is that my windows OS handles the temporary files that are created with tempnam and puts it in the C:\Windows\Temp directory with its own assigned name ("phr" follwed by 4 random characters ".tmp"). Anyways you can take a look at my code below.


$username = '51191RETS';
$password = '*****'; 
require_once('vendor/autoload.php');
//RETS URL
$rets_url = 'http://matrixrets.alamls.net/rets/';
//Login Page URL
$login_page = $rets_url . 'login.ashx'; 
$config = new \PHRETS\Configuration;
$config->setLoginUrl($login_page);
$config->setUsername($username);
$config->setPassword($password);
$config->setHttpAuthenticationMethod('digest');
$rets = new \PHRETS\Session($config); 
$rets->getClient()->setDefaultOption('config', [
'curl' => [
CURLOPT_COOKIEFILE => tempnam('/tmp', 'phrets')
]
]); 
$connect = $rets->Login();
$system = $rets->GetSystemMetadata();
vardump($system);
So on that note, any ideas or suggestions on what I am doing wrong or how i could fix this?

Also as a complete sidenote, I went digging for answers to this issue on my own (like i typically would be doing), when i go through a web browser and look at the request/response header i see that it is using digest authentication, and although the web browser doesn't feed me all the details of the original exchange of information, i can see this in the request headers my browser sends back:

Authorization: 

Digest username="51191RETS", realm="MATRIX", nonce="MjAxNi0wNS0yNSAxNDo1Mzo0NC4zNjI", uri="/rets/login.ashx", algorithm=MD5, response="12ec9a9ec35586b4684925d9382e4592", opaque="0000000000000000", qop="auth", nc=00000001, cnonce="016405e4c2b627a6"

Just figured i would pass this part along as it may or may not be relevant to understanding what is going on with the authentication.

Gregg Moore

unread,
May 25, 2016, 11:40:21 AM5/25/16
to phr...@googlegroups.com
Patrick,

Are you developing local? if not, what type go hosting are you using?
It sounds like you may need to check to be sure the proper ports are open.

Gregg Moore
Application Programmer/Web Developer
AT&T/iPhone :: 910.685.5055

Facebook :: facebook/GreggMoore23
Twitter :: MadRhino23

"Never trust a computer you can’t throw out a window."
Steve Wozniak

--
You received this message because you are subscribed to the Google Groups "PHRETS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phrets+un...@googlegroups.com.
To post to this group, send email to phr...@googlegroups.com.
Visit this group at https://groups.google.com/group/phrets.
For more options, visit https://groups.google.com/d/optout.

Patrick Howe

unread,
May 25, 2016, 12:00:22 PM5/25/16
to PHRETS
Hi Gregg,

Yes i am developing locally on a windows desktop. I just tried turning off windows firewall, which didnt help. Also it will connect just fine using multiple web browsers and the rets connect client application from this machine, so i don't believe there's any port issues (especially not over port 80 which is what i believe is used with http authentication). I will say that i have tried writing my own Curl connection in PHP and have had no luck with it either.

Also just wanted to say thanks for the timely response.

Patrick

Gregg Moore

unread,
May 25, 2016, 12:04:08 PM5/25/16
to phr...@googlegroups.com
Ok,

Be sure the path to your cookie file is absolute, being in a local environment.
RETS usually uses port 6103.. someone please correct me if I am wrong or clarify for Patrick.

Thanks!


Gregg Moore
Application Programmer/Web Developer
AT&T/iPhone :: 910.685.5055

Facebook :: facebook/GreggMoore23
Twitter :: MadRhino23

"Never trust a computer you can’t throw out a window."
Steve Wozniak

Patrick Howe

unread,
May 25, 2016, 12:38:19 PM5/25/16
to PHRETS
Hi Gregg,

I updated the code to ensure that the cookie file is not the issue.


//RETS URL

//Login Page URL
$login_page = $rets_url . 'login.ashx';

$config = new \PHRETS\Configuration;
$config->setLoginUrl($login_page);
$config->setUsername($username);
$config->setPassword($password);
$config->setHttpAuthenticationMethod('digest');

$rets = new \PHRETS\Session($config);

$temp_cookie_file = 'C:\wamp\www\rets\tmp\rets_cookie.tmp';

if(! file_exists($temp_cookie_file)){
echo 'File Not Found: '. $temp_cookie_file;
} elseif(! is_writable($temp_cookie_file)) {
echo 'File Not Writable: ' . $temp_cookie_file;
}

$rets->getClient()->setDefaultOption('config', [
'curl' => [
CURLOPT_COOKIEFILE => $temp_cookie_file
]
]);

$connect = $rets->Login();

$system = $rets->GetSystemMetadata();

vardump($system);

Its not throwing an error with the cookie file (ensuring that php can indeed read and write to the file). And ive tried this with a number of different names / file paths and all are giving me the same result. I have no good way of knowing whether this port is the issue or not. I can run a scan on ports in use on my PC, but 6103 isnt showing and i doubt it will because it would have to be temporarily opened and then closed when the PHP script is active/running.

Any ideas on what i could try?

Mariano Iglesias

unread,
May 25, 2016, 1:23:05 PM5/25/16
to phr...@googlegroups.com
Are you sure you are not being restricted by ip?

--

Gennadiy Kofman

unread,
May 25, 2016, 1:35:29 PM5/25/16
to PHRETS
Are you able to log in on your production server?  Lets figure out if it's a problem with a windows environment or a rets problem first.

Also, try your credentials through here:
http://retsmd.com/auth/

Troy built that to use the phrets 2.x login process.  The regular rets md still uses 1.x

I have a few matrix rets feeds and I don't need to set the cookie. (I don't have the one your trying though).  The only difference I have is that I set the rets version as one of the configs.

Gregg Moore

unread,
May 25, 2016, 1:37:53 PM5/25/16
to phr...@googlegroups.com
I believe Patrick mentioned in an earlier email that he had no issues connecting via restmd.com. So, I’m guessing it has to with his local environment/connection. Something is blocking it.

Gregg Moore
Application Programmer/Web Developer
AT&T/iPhone :: 910.685.5055

Facebook :: facebook/GreggMoore23
Twitter :: MadRhino23

"Never trust a computer you can’t throw out a window."
Steve Wozniak

Gennadiy Kofman

unread,
May 25, 2016, 1:40:19 PM5/25/16
to PHRETS
Yeah, I saw that, but I also had no problem logging in through retsmd with crmls but couldn't log in through http://retsmd.com/auth/ because they used different versions of phrets.

Gregg Moore

unread,
May 25, 2016, 1:43:06 PM5/25/16
to phr...@googlegroups.com
Gotcha….

Gregg Moore
Application Programmer/Web Developer
AT&T/iPhone :: 910.685.5055

Facebook :: facebook/GreggMoore23
Twitter :: MadRhino23

"Never trust a computer you can’t throw out a window."
Steve Wozniak

Patrick Howe

unread,
May 25, 2016, 1:52:40 PM5/25/16
to PHRETS
So i went and created a temporary beta site on my linux server (production), and i ran the same script on it and it connected just fine. If i have to i can continue using this to do my development but it still irritates me that I can't get it to run on my windows environment. I spoke with the network guys at the company i work at, and they said there are no outbound ports being blocked by us, and i dont have firewall up on my local machine. The only way that port is getting blocked is if the mls's rets server is blocking that port. It also doesnt add up that its an IP block either, since retsmd is working (also tried and confirms that the retsmd.com/auth/ works too).

Thanks for all the responses, it has been helpful.

ra...@thebestmedia.com

unread,
Feb 4, 2019, 12:07:17 PM2/4/19
to PHRETS
Hey Guys, I am not able to login. I verified it using retsmd.com and even /auth url.  i am getting CURL error 7. 

Uncaught PHP Exception GuzzleHttp\Exception\ConnectException: "cURL error 7: Failed to connect to retsau.torontomls.net port 6103: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)" at /home/thebestmedia/public_html/treb/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php line 185 {"exception":"[object] (GuzzleHttp\\Exception\\ConnectException(code: 0): cURL error 7: Failed to connect to retsau.torontomls.net port 6103: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) at /home/thebestmedia/public_html/treb/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185)"} []

Do I need to open any ports on my Ubuntu server? Any help is appreciated.
Reply all
Reply to author
Forward
0 new messages