arubacao's avatar

HTTP Basic Auth in Lumen 5.2

I'm having trouble upgrading from Lumen 5.1 to Lumen 5.2. Currently i'm authenticating API requests with HTTP Basic Auth as described in Laravel 5.1 Stateless http basic auth docs (only for lumen, but with the same components). Obviously a lot changed to the AuthManager (or for me: to the Facade) . This call: Auth::onceBasic() will return an exception like this:

[2016-03-17 01:58:53] lumen.ERROR: ErrorException: Undefined index: provider in /home/vagrant/Code/vendor/illuminate/auth/AuthManager.php:152
Stack trace:
#0 /home/vagrant/Code/vendor/illuminate/auth/AuthManager.php(152): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(8, 'Undefined index...', '/home/vagrant/C...', 152, Array)
#1 /home/vagrant/Code/vendor/illuminate/auth/AuthManager.php(92): Illuminate\Auth\AuthManager->createTokenDriver('api', Array)
#2 /home/vagrant/Code/vendor/illuminate/auth/AuthManager.php(70): Illuminate\Auth\AuthManager->resolve('api')
#3 /home/vagrant/Code/vendor/illuminate/auth/AuthManager.php(282): Illuminate\Auth\AuthManager->guard()
#4 /home/vagrant/Code/vendor/illuminate/support/Facades/Facade.php(215): Illuminate\Auth\AuthManager->__call('user', Array)
#5 /home/vagrant/Code/app/Exceptions/Handler.php(47): Illuminate\Support\Facades\Facade::__callStatic('user', Array)
#6 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(75): App\Exceptions\Handler->report(Object(ErrorException))
#7 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(34): Laravel\Lumen\Routing\Pipeline->handleException(Object(Illuminate\Http\Request), Object(ErrorException))
#8 [internal function]: Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#9 /home/vagrant/Code/vendor/illuminate/pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#10 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(621): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(567): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#12 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(542): Laravel\Lumen\Application->callLumenControllerWithMiddleware(Object(App\Http\Controllers\Users\UserLoginController), 'checkLogin', Array, Array)
#13 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(521): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\Users\UserLoginController), 'checkLogin', Array)
#14 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(489): Laravel\Lumen\Application->callControllerAction(Array)
#15 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(474): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#16 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(376): Laravel\Lumen\Application->handleFoundRoute(Array)
#17 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Illuminate\Http\Request))
#18 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 /home/vagrant/Code/app/Http/Middleware/SubversionMiddleware.php(32): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#20 [internal function]: App\Http\Middleware\SubversionMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#21 /home/vagrant/Code/vendor/illuminate/pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#22 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#24 [internal function]: Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#25 /home/vagrant/Code/vendor/illuminate/pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#26 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(621): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#27 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(382): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#28 /home/vagrant/Code/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(327): Laravel\Lumen\Application->dispatch(NULL)
#29 /home/vagrant/Code/public/index.php(28): Laravel\Lumen\Application->run()

Illuminate\Auth\AuthManager->resolve('api') it seems like Auth::onceBasic doesn't even try to call onceBasic.

Does anyone have similar problems or ideas on how to fix / reintegrate it?

Cheers, Chris

0 likes
3 replies
arubacao's avatar

Ok in the config file auth.php the guard driver is set to token

    'guards' => [
        'api' => ['driver' => 'token'],
    ],

so authentication will happen with the TokenGuard and the token guard doesn't support Auth::onceBasic The SessionGuardhas got this method, but if i choose session as the guard driver is get this error:

Class session.store does not exist

Which makes sense since Lumen 5.2 doesn't support sessions anymore.

So still my question remains: how to authenticate with http basic with in lumen 5.2?

1 like
jekinney's avatar

Few of these questions have come up. I currently am using 5.1 for a few projects and imo if it works....

Any case, in 5.1 almost all of the Laravel framework is in the vendor folder under Laravel. If it's still there you should be able to update you composer file to auto load it or in your conf file use the full path to class. If not maybe you can require in that class or copy paste it in your app.

Please or to participate in this conversation.