{"action":"opened","issue":{"url":"https://api.github.com/repos/dingo/api/issues/720","labels_url":"https://api.github.com/repos/dingo/api/issues/720/labels{/name}","comments_url":"https://api.github.com/repos/dingo/api/issues/720/comments","events_url":"https://api.github.com/repos/dingo/api/issues/720/events","html_url":"https://github.com/dingo/api/issues/720","id":116034304,"number":720,"title":"Basic Auth fails with PHPUnit","user":{"login":"jinseokoh","id":1305356,"avatar_url":"https://avatars.githubusercontent.com/u/1305356?v=3","gravatar_id":"","url":"https://api.github.com/users/jinseokoh","html_url":"https://github.com/jinseokoh","followers_url":"https://api.github.com/users/jinseokoh/followers","following_url":"https://api.github.com/users/jinseokoh/following{/other_user}","gists_url":"https://api.github.com/users/jinseokoh/gists{/gist_id}","starred_url":"https://api.github.com/users/jinseokoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jinseokoh/subscriptions","organizations_url":"https://api.github.com/users/jinseokoh/orgs","repos_url":"https://api.github.com/users/jinseokoh/repos","events_url":"https://api.github.com/users/jinseokoh/events{/privacy}","received_events_url":"https://api.github.com/users/jinseokoh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-10T06:01:31Z","updated_at":"2015-11-10T06:01:31Z","closed_at":null,"body":"\r\nI can't make basic.auth work when testing with PHPUnit. It fails with 401 \"Invalid authentication credentials.\"\r\n\r\n\r\n    .Dingo\\Api\\Http\\Response {#625\r\n      #binding: null\r\n      +original: array:3 [\r\n        \"message\" => \"Invalid authentication credentials.\"\r\n        \"status_code\" => 401\r\n        \"debug\" => array:4 [\r\n          \"line\" => 55\r\n          \"file\" => \"/home/vagrant/sites/joara2/vendor/dingo/api/src/Auth/Provider/Basic.php\"\r\n          \"class\" => \"Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException\"\r\n          \"trace\" => array:56 [\r\n            0 => \"#0 /home/vagrant/sites/joara2/vendor/dingo/api/src/Auth/Auth.php(82): Dingo\\Api\\Auth\\Provider\\Basic->authenticate(Object(Dingo\\Api\\Http\\Request), Object(Dingo\\Api\\Routing\\Route))\"\r\n            1 => \"#1 /home/vagrant/sites/joara2/vendor/dingo/api/src/Http/Middleware/Auth.php(50): Dingo\\Api\\Auth\\Auth->authenticate(Array)\"\r\n            2 => \"#2 [internal function]: Dingo\\Api\\Http\\Middleware\\Auth->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            3 => \"#3 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            4 => \"#4 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            5 => \"#5 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))\"\r\n            6 => \"#6 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(706): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\"\r\n            7 => \"#7 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Dingo\\Api\\Http\\Request))\"\r\n            8 => \"#8 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(631): Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))\"\r\n            9 => \"#9 /home/vagrant/sites/joara2/vendor/dingo/api/src/Routing/Adapter/Laravel.php(65): Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))\"\r\n            10 => \"#10 /home/vagrant/sites/joara2/vendor/dingo/api/src/Routing/Router.php(530): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')\"\r\n            11 => \"#11 /home/vagrant/sites/joara2/vendor/dingo/api/src/Http/Middleware/Request.php(110): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))\"\r\n            12 => \"#12 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            13 => \"#13 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))\"\r\n            14 => \"#14 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            15 => \"#15 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            16 => \"#16 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            17 => \"#17 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            18 => \"#18 [internal function]: Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            19 => \"#19 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            20 => \"#20 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            21 => \"#21 [internal function]: Illuminate\\Session\\Middleware\\StartSession->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            22 => \"#22 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            23 => \"#23 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            24 => \"#24 [internal function]: Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            25 => \"#25 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            26 => \"#26 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            27 => \"#27 [internal function]: Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            28 => \"#28 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            29 => \"#29 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            30 => \"#30 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))\"\r\n            31 => \"#31 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            32 => \"#32 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))\"\r\n            33 => \"#33 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))\"\r\n            34 => \"#34 /home/vagrant/sites/joara2/vendor/dingo/api/src/Http/Middleware/Request.php(111): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\"\r\n            35 => \"#35 /home/vagrant/sites/joara2/vendor/dingo/api/src/Http/Middleware/Request.php(89): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))\"\r\n            36 => \"#36 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))\"\r\n            37 => \"#37 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)\"\r\n            38 => \"#38 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\"\r\n            39 => \"#39 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\"\r\n            40 => \"#40 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\"\r\n            41 => \"#41 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))\"\r\n            42 => \"#42 /home/vagrant/sites/joara2/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php(393): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))\"\r\n            43 => \"#43 /home/vagrant/sites/joara2/tests/NovelTest.php(274): Illuminate\\Foundation\\Testing\\TestCase->call('POST', '/v1/books/novel', Array, Array, Array, Array)\"\r\n            44 => \"#44 [internal function]: NovelTest->post_novel_with_photo()\"\r\n            45 => \"#45 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestCase.php(909): ReflectionMethod->invokeArgs(Object(NovelTest), Array)\"\r\n            46 => \"#46 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestCase.php(768): PHPUnit_Framework_TestCase->runTest()\"\r\n            47 => \"#47 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestResult.php(612): PHPUnit_Framework_TestCase->runBare()\"\r\n            48 => \"#48 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestCase.php(724): PHPUnit_Framework_TestResult->run(Object(NovelTest))\"\r\n            49 => \"#49 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))\"\r\n            50 => \"#50 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/Framework/TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\"\r\n            51 => \"#51 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\"\r\n            52 => \"#52 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/TextUI/Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)\"\r\n            53 => \"#53 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/src/TextUI/Command.php(100): PHPUnit_TextUI_Command->run(Array, true)\"\r\n            54 => \"#54 /home/vagrant/sites/joara2/vendor/phpunit/phpunit/phpunit(47): PHPUnit_TextUI_Command::main()\"\r\n            55 => \"#55 {main}\"\r\n          ]\r\n        ]\r\n      ]\r\n\r\n\r\nMy API still works fine when testing with Postman. Anyone have any clues?\r\n\r\n\r\nconfig/api.php\r\n\r\n    <?php\r\n\r\n    return [\r\n        :\r\n        'version' => 'v1',\r\n        'prefix' => 'v1',\r\n        'domain' => null,\r\n        'name' => 'MyAPI',\r\n        'strict' => false,\r\n        'debug' => true,\r\n        :\r\n    ];\r\n\r\n\r\nAppServiceProvider.php\r\n\r\n    <?php\r\n\r\n    namespace App\\Providers;\r\n\r\n    use Illuminate\\Support\\ServiceProvider;\r\n    use Dingo\\Api\\Auth\\Provider\\Basic;\r\n\r\n    class AppServiceProvider extends ServiceProvider\r\n    {\r\n        public function boot()\r\n        {\r\n            $this->app['api.auth']->extend('basic', function ($app) {\r\n                return new Basic($app['auth'], 'email');\r\n            });\r\n\r\n        }\r\n        :\r\n    }\r\n\r\nroutes.php\r\n\r\n    $api->version('v1', [ 'namespace' => 'App\\Http\\Controllers' ], function($api) {\r\n        $api->group([ 'middleware' => 'api.auth' ], function($api) {\r\n\r\n            /* users */\r\n            $api->get('users',               [ 'as' => 'users.index',         'uses' => 'UserController@index' ]);\r\n            $api->get('users/{id}',          [ 'as' => 'users.show',          'uses' => 'UserController@show' ]);\r\n            $api->post('users',              [ 'as' => 'users.store',         'uses' => 'UserController@create' ]);\r\n        });\r\n    });\r\n\r\nUserTest.php\r\n\r\n    /**\r\n     * @test\r\n     */\r\n    public function get_all_users()\r\n    {\r\n\r\n            $header = [ 'HTTP_Authorization' => 'Basic cXVlZW5Aam9hcmEuY29tOnRlc3Q=' ];\r\n            $this->get('/v1/users', $header)->seeStatusCode(200);\r\n    }\r\n\r\n"}}