Lumen authentication

I just can't get Lumen authentication to work at all.

I have a new installation and try to follow the docs here:

https://lumen.laravel.com/docs/5.2/authentication

I uncommented the line AuthProviderin the file app.php(along with everything else, facade, etc.). Then in a simple controller I just do dd(Auth::use()).

I just can't get around this error:

Undefined index: provider
in AuthManager.php line 152
at Application->Laravel\Lumen\Concerns\{closure}('8', 'Undefined index: provider', '/home/vagrant/Code/gryd/api.gryd.com/vendor/illuminate/auth/AuthManager.php', '152', array('name' => 'api', 'config' => array('driver' => 'token'))) in AuthManager.php line 152

Any ideas?

EDIT:

Since someone asked for sample code.

  • Install Lumen
  • Uncomment everything in app.php
  • Put this in the routes:

    $ app-> get ('/ api / v1 / users / {id}', function () {dd (\ Auth :: user ());});

+4
source share
2 answers

, , api .env. token .

Auth::viaRequest('api', functi Auth::viaRequest('token', funct.

+1

, , , . , Lumen.

routeMiddleware AuthServiceProvider, bootstrap/app.php.

$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

$app->register(App\Providers\AuthServiceProvider::class);

vendor/laravel/lumen-framework/config/auth.php config/auth.php. config, .

(defaults, guards, providers, passwords). .

guard ABC.

'defaults' => [
    'guard' => env('AUTH_GUARD', 'ABC'),
],

ABC token XYZ .

'guards' => [
    'ABC' => [
        'driver' => 'token', 
        'provider' => 'XYZ'
    ],
],

XYZ eloquent App\User::class .

'providers' => [
    'XYZ' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
    ],
],

, auth , .

$app->group(['middleware' => 'auth'], function () use ($app) {

, , . api_token users , TokenGuard.

, AuthServiceProvider $this->app['auth']->viaRequest('api', function ($request) { .

+6

All Articles