# Basic Authentication is not working

**URL:** https://community.wowza.com/t/basic-authentication-is-not-working/34374
**Category:** Wowza Developer Dojo
**Tags:** wowza-streaming-server-java-api
**Created:** [March 4, 2010, 8:51am UTC](https://community.wowza.com/t/basic-authentication-is-not-working/34374 "2010-03-04T08:51:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Dario\_Mindoro](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dario\_Mindoro](https://community.wowza.com/u/Dario_Mindoro)
#### Post date: [March 4, 2010, 8:51am UTC](https://community.wowza.com/t/basic-authentication-is-not-working/34374/1 "2010-03-04T08:51:00Z")

</div>

Hi Charlie,

I just notice that the basic authentication is not working on the wowza vhost, when I set the authentication method to basic it just set to none or no authentication, I need to change the Digest method to basic method because I want my php script to grab xml info and display it on the site, the digest method is a little complicated and random so I prefer the basic method

I also tried to create another method on the authentication.xml for basic just like below

[HTML]

admin-basic

Admin Basic Authentication

com.wowza.wms.authentication.AuthenticateBasic

passwordFile

${com.wowza.wms.context.VHostConfigHome}/conf/admin.password

realm

Wowza Media Systems

[/HTML]

Both admin.password and publish.password has been set also

---

<div class="post-metadata">

### Author: ![Charlie\_Good](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/charlie_good/32/383_2.png) [@Charlie\_Good](https://community.wowza.com/u/Charlie_Good)
#### Post date: [March 4, 2010, 4:47am UTC](https://community.wowza.com/t/basic-authentication-is-not-working/34374/2 "2010-03-04T04:47:19Z")

</div>

We only support digest for HTTP authentication at this time. We may add basic in a future release.

Charlie

---

<div class="post-metadata">

### Author: ![Chris\_Trainor](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@Chris\_Trainor](https://community.wowza.com/u/Chris_Trainor)
#### Post date: [March 4, 2010, 11:31am UTC](https://community.wowza.com/t/basic-authentication-is-not-working/34374/3 "2010-03-04T11:31:37Z")

</div>

There is some example code here on how to do digest auth while fetching URL’s using file\_get\_contents.

[http://www.php.net/manual/en/function.fopen.php#51592](http://www.php.net/manual/en/function.fopen.php#51592)

–Chris

---

<div class="post-metadata">

### Author: ![Dario\_Mindoro](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dario\_Mindoro](https://community.wowza.com/u/Dario_Mindoro)
#### Post date: [March 6, 2010, 10:00am UTC](https://community.wowza.com/t/basic-authentication-is-not-working/34374/4 "2010-03-06T10:00:25Z")

</div>

Hi christr,

Thanks a lot, this is perfect , I did googling out this code for several days already but no luck, I did modify the code to fit on my needs, below is what I have come out, I added code sanitation to eliminate those extra header response from server so that only pure xml will be feed to xmlDOM.

[PHP]

\<?php $retstr=readHTTPDigestAuthenticatedFile("SERVERIP","8086","connectioncounts/","USERNAME","PASSWORD"); //grab only the xml content $GrabStart = ''; $GrabEnd = ''; $GrabData = eregi("$GrabStart(.\*)$GrabEnd", $retstr, $DataGrabed); $xml\_data="\<?xml version=\"1.0\"?\>".$DataGrabed[1]."";

$doc = new DOMDocument();

$doc-\>loadXML($xml\_data);

$wms = $doc-\>getElementsByTagName(‘WowzaMediaServer’);

$currentlistener = $wms-\>item(0)-\>getElementsByTagName(“ConnectionsCurrent”)-\>item(0)-\>nodeValue;

$listenerhits = $wms-\>item(0)-\>getElementsByTagName(“ConnectionsTotal”)-\>item(0)-\>nodeValue;

echo “Current Listeners: $currentlistener   
 Connection Count: $listenerhits”;

function readHTTPDigestAuthenticatedFile($host,$port,$file,$username,$password)

{

if (!$fp=fsockopen($host,$port, $errno, $errstr, 15))

return false;

//first do the non-authenticated header so that the server

//sends back a 401 error containing its nonce and opaque

$out = “GET /$file HTTP/1.1\r\n”;

$out .= “Host: $host\r\n”;

$out .= “Connection: Close\r\n\r\n”;

fwrite($fp, $out);

//read the reply and look for the WWW-Authenticate element

while (!feof($fp))

{

$line=fgets($fp, 512);

if (strpos($line,“WWW-Authenticate:”)!==false)

$authline=trim(substr($line,18));

}

fclose($fp);

//split up the WWW-Authenticate string to find digest-realm,nonce and opaque values

//if qop value is presented as a comma-seperated list (e.g auth,auth-int) then it won’t be retrieved correctly

//but that doesn’t matter because going to use ‘auth’ anyway

$authlinearr=explode(",",$authline);

$autharr=array();

foreach ($authlinearr as $el)

{

$elarr=explode("=",$el);

//the substr here is used to remove the double quotes from the values

$autharr[trim($elarr[0])]=substr($elarr[1],1,strlen($elarr[1])-2);

}

//these are all the vals required from the server

$nonce=$autharr[‘nonce’];

$opaque=$autharr[‘qop’]; //opaque

$drealm=$autharr[‘Digest realm’];

//client nonce can be anything since this authentication session is not going to be persistent

//likewise for the cookie - just call it MyCookie

$cnonce=“sausages”;

//calculate the hashes of A1 and A2 as described in RFC 2617

$a1="$username:$drealm:$password";$a2=“GET:/$file”;

$ha1=md5($a1);$ha2=md5($a2);

//calculate the response hash as described in RFC 2617

$concat = $ha1.’:’.$nonce.’:00000001:’.$cnonce.’:auth:’.$ha2;

$response=md5($concat);

//put together the Authorization Request Header

$out = “GET /$file HTTP/1.1\r\n”;

$out .= “Host: $host\r\n”;

$out .= “Connection: Close\r\n”;

$out .= “Cookie: cookie=MyCookie\r\n”;

$out .= “Authorization: Digest username=”$username", realm="$drealm", qop=“auth”, algorithm=“MD5”, uri="/$file", nonce="$nonce", nc=00000001, cnonce="$cnonce", opaque="$opaque", response="$response"\r\n\r\n";

if (!$fp=fsockopen($host,$port, $errno, $errstr, 15))

return false;

fwrite($fp, $out);

$str="";

//read in a string which is the contents of the required file

while (!feof($fp))

{

$str.=fgets($fp, 512);

}

fclose($fp);

return $str;

}

?\>

[/PHP]

Thanks also charlie, at least now I will only use Digest type authentication method
