private function getServerTokens($qop = DigestAuth::QOP_AUTH) { $this->auth->requireLogin(); switch ($qop) { case DigestAuth::QOP_AUTH: $qopstr = 'auth'; break; case DigestAuth::QOP_AUTHINT: $qopstr = 'auth-int'; break; default: $qopstr = 'auth,auth-int'; break; } $test = preg_match('/Digest realm="' . self::REALM . '",qop="' . $qopstr . '",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', $this->response->headers['WWW-Authenticate'], $matches); $this->assertTrue($test == true, 'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->headers['WWW-Authenticate']); $nonce = $matches[1]; $opaque = $matches[2]; // Reset our environment $this->setUp(); $this->auth->setQOP($qop); return array($nonce, $opaque); }
<?php // !!!! Make sure the Sabre directory is in the include_path !!! // example: // set_include_path('lib/' . PATH_SEPARATOR . get_include_path()); // settings date_default_timezone_set('Canada/Eastern'); // Files we need require_once 'vendor/autoload.php'; $u = 'admin'; $p = '1234'; $auth = new \Sabre\HTTP\DigestAuth(); $auth->init(); if ($auth->getUsername() != $u || !$auth->validatePassword($p)) { $auth->requireLogin(); echo "Authentication required\n"; die; }