{"action":"created","issue":{"url":"https://api.github.com/repos/fruux/sabre-dav/issues/842","repository_url":"https://api.github.com/repos/fruux/sabre-dav","labels_url":"https://api.github.com/repos/fruux/sabre-dav/issues/842/labels{/name}","comments_url":"https://api.github.com/repos/fruux/sabre-dav/issues/842/comments","events_url":"https://api.github.com/repos/fruux/sabre-dav/issues/842/events","html_url":"https://github.com/fruux/sabre-dav/issues/842","id":156672822,"number":842,"title":"Authentication issue","user":{"login":"nhphuc392","id":19264169,"avatar_url":"https://avatars.githubusercontent.com/u/19264169?v=3","gravatar_id":"","url":"https://api.github.com/users/nhphuc392","html_url":"https://github.com/nhphuc392","followers_url":"https://api.github.com/users/nhphuc392/followers","following_url":"https://api.github.com/users/nhphuc392/following{/other_user}","gists_url":"https://api.github.com/users/nhphuc392/gists{/gist_id}","starred_url":"https://api.github.com/users/nhphuc392/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhphuc392/subscriptions","organizations_url":"https://api.github.com/users/nhphuc392/orgs","repos_url":"https://api.github.com/users/nhphuc392/repos","events_url":"https://api.github.com/users/nhphuc392/events{/privacy}","received_events_url":"https://api.github.com/users/nhphuc392/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-25T06:28:31Z","updated_at":"2016-05-26T16:18:35Z","closed_at":null,"body":"I tried to build a client with these settings below, but always get the message:\r\n **\"3.1.3 Sabre\\DAV\\Exception\\NotAuthenticated Username1 or password was incorrect \" [\"statusCode\"]=> int(401)\"**\r\nTried with password in plain text and also MD5 password (digesta) but won't work.\r\n\r\nBelow is my addressbookserver.php configuration:\r\n\r\n```\r\n/*\r\n\r\nAddressbook/CardDAV server example\r\n\r\nThis server features CardDAV support\r\n\r\n*/\r\n\r\n// settings\r\ndate_default_timezone_set('Asia/Ho_Chi_Minh');\r\n\r\n// Make sure this setting is turned on and reflect the root url for your WebDAV server.\r\n// This can be for example the root / or a complete path to your server script\r\n$baseUri = '/sabredav/addressbookserver.php';\r\n\r\n/* Database */\r\n//$pdo = new PDO('sqlite:data/db.sqlite');\r\n$pdo = new \\PDO('mysql:host=localhost;dbname=sabre','root','');\r\n$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n\r\n//Mapping PHP errors to exceptions\r\nfunction exception_error_handler($errno, $errstr, $errfile, $errline) {\r\n    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);\r\n}\r\nset_error_handler(\"exception_error_handler\");\r\n\r\n// Autoloader\r\nrequire_once 'vendor/autoload.php';\r\n\r\n// Backends\r\n$authBackend      = new Sabre\\DAV\\Auth\\Backend\\PDO($pdo);\r\n$principalBackend = new Sabre\\DAVACL\\PrincipalBackend\\PDO($pdo);\r\n$carddavBackend   = new Sabre\\CardDAV\\Backend\\PDO($pdo);\r\n//$caldavBackend    = new Sabre\\CalDAV\\Backend\\PDO($pdo);\r\n\r\n// Setting up the directory tree //\r\n$nodes = [\r\n    new Sabre\\DAVACL\\PrincipalCollection($principalBackend),\r\n//    new Sabre\\CalDAV\\CalendarRoot($authBackend, $caldavBackend),\r\n    new Sabre\\CardDAV\\AddressBookRoot($principalBackend, $carddavBackend),\r\n];\r\n\r\n// The object tree needs in turn to be passed to the server class\r\n$server = new Sabre\\DAV\\Server($nodes);\r\n$server->setBaseUri($baseUri);\r\n\r\n// Plugins\r\n$server->addPlugin(new Sabre\\DAV\\Auth\\Plugin($authBackend));\r\n$server->addPlugin(new Sabre\\DAV\\Browser\\Plugin());\r\n//$server->addPlugin(new Sabre\\CalDAV\\Plugin());\r\n$server->addPlugin(new Sabre\\CardDAV\\Plugin());\r\n$server->addPlugin(new Sabre\\DAVACL\\Plugin());\r\n$server->addPlugin(new Sabre\\DAV\\Sync\\Plugin());\r\n\r\n// And off we go!\r\n$server->exec();\r\n```\r\n\r\nBelow is my addressbookclient.php configuration:\r\n\r\n```\r\n// settings\r\ndate_default_timezone_set('Asia/Ho_Chi_Minh');\r\n\r\n// Make sure this setting is turned on and reflect the root url for your WebDAV server.\r\n// This can be for example the root / or a complete path to your server script\r\n$baseUri = 'http://localhost:8081/sabredav/addressbookserver.php';\r\n\r\nuse Sabre\\DAV\\Client;\r\n\r\ninclude 'vendor/autoload.php';\r\n\r\n$settings = array(\r\n    'baseUri' => $baseUri,\r\n    'userName' => 'admin',\r\n    'password' => 'admin',\r\n    'authType' => Sabre\\DAV\\Client::AUTH_DIGEST,\r\n);\r\n\r\n$client = new Client($settings);\r\n\r\n$response = $client->request('GET'); \r\n\r\nvar_dump($response);\r\n```\r\n\r\nI had make a var_dump in **validate()** function to try to output the value:\r\n\r\n```\r\n    /**\r\n     * Validates the digest challenge\r\n     *\r\n     * @return bool\r\n     */\r\n    protected function validate() {\r\n\r\n        $A2 = $this->request->getMethod() . ':' . $this->digestParts['uri'];\r\n\r\n        if ($this->digestParts['qop'] == 'auth-int') {\r\n            // Making sure we support this qop value\r\n            if (!($this->qop & self::QOP_AUTHINT)) return false;\r\n            // We need to add an md5 of the entire request body to the A2 part of the hash\r\n            $body = $this->request->getBody($asString = true);\r\n            $this->request->setBody($body);\r\n            $A2 .= ':' . md5($body);\r\n        } else {\r\n\r\n            // We need to make sure we support this qop value\r\n            if (!($this->qop & self::QOP_AUTH)) return false;\r\n        }\r\n\r\n        $A2 = md5($A2);\r\n\r\n        $validResponse = md5(\"{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}\");\r\n        var_dump(\"digestParts['response']=\".$this->digestParts['response']);\r\n        var_dump(\"validResponse=\".$validResponse);\r\n        return $this->digestParts['response'] == $validResponse;\r\n\r\n    }\r\n```\r\n\r\n\r\nAnd the output value here:\r\n\r\n```array(3) { [\"body\"]=> string(414) \"string(56) \"digestParts['response']=754c5eb5c3362b0fe0b9774b9fa11139\" string(46) \"validResponse=a4b80df54e14558902c9aa86aa8f52a6\" 3.1.3 Sabre\\DAV\\Exception\\NotAuthenticated Username1 or password was incorrect \" [\"statusCode\"]=> int(401) [\"headers\"]=> array(6) { [\"date\"]=> array(1) { [0]=> string(29) \"Wed, 25 May 2016 06:24:12 GMT\" } [\"server\"]=> array(1) { [0]=> string(47) \"Apache/2.4.12 (Win32) OpenSSL/1.0.1m PHP/5.5.27\" } [\"x-powered-by\"]=> array(1) { [0]=> string(10) \"PHP/5.5.27\" } [\"www-authenticate\"]=> array(1) { [0]=> string(98) \"Digest realm=\"SabreDAV\",qop=\"auth\",nonce=\"5745450c61db8\",opaque=\"df58bdff8cf60599c939187d0b5c54de\"\" } [\"content-length\"]=> array(1) { [0]=> string(3) \"414\" } [\"content-type\"]=> array(1) { [0]=> string(30) \"application/xml; charset=utf-8\" } } }```\r\n\r\n\r\nPlease help me to solve this issue, thank you all.\r\n\r\n\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/34551717-authentication-issue?utm_campaign=plugin&utm_content=tracker%2F294006&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F294006&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/fruux/sabre-dav/issues/comments/221920348","html_url":"https://github.com/fruux/sabre-dav/issues/842#issuecomment-221920348","issue_url":"https://api.github.com/repos/fruux/sabre-dav/issues/842","id":221920348,"user":{"login":"evert","id":178960,"avatar_url":"https://avatars.githubusercontent.com/u/178960?v=3","gravatar_id":"","url":"https://api.github.com/users/evert","html_url":"https://github.com/evert","followers_url":"https://api.github.com/users/evert/followers","following_url":"https://api.github.com/users/evert/following{/other_user}","gists_url":"https://api.github.com/users/evert/gists{/gist_id}","starred_url":"https://api.github.com/users/evert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evert/subscriptions","organizations_url":"https://api.github.com/users/evert/orgs","repos_url":"https://api.github.com/users/evert/repos","events_url":"https://api.github.com/users/evert/events{/privacy}","received_events_url":"https://api.github.com/users/evert/received_events","type":"User","site_admin":false},"created_at":"2016-05-26T16:18:35Z","updated_at":"2016-05-26T16:18:35Z","body":"Hi! Could your try calling `var_dump` on `$digestParts`? Also, are you sure that your username and password is `admin`? Can you access the sabre/dav server from a browser?\r\n\r\nLastly, what realm are you using? If you used the default `SabreDAV` realm your md5 hash for admin:admin should be `87fd274b7b6c01e48d7c2f965da8ddf7`, but neither of your hashes match that."}}
{"actor":{"display_login":"evert"}}