laravel passport - Lumen auth:api always comes back Unauthorized -
bootstrap/app.php (the important bits)
$app->routemiddleware([ 'auth' => app\http\middleware\authenticate::class, ]); $app->register(app\providers\authserviceprovider::class); $app->configure('auth'); config/auth.php
'guards' => [ 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], 'token' => [ 'driver' => 'token', 'provider' => 'users', ], ], authserviceprovider.php
public function boot() { $this->app['auth']->viarequest('api', function ($request) { return user::first(); //if ($request->input('api_token')) { //return user::where('api_token', $request->input('api_token'))->first(); //} }); } middleware/authenticate.php
public function handle($request, closure $next, $guard = null) { if ($this->auth->guard($guard)->guest()) { return response('unauthorized.', 401); } return $next($request); } route:
get request /api/v1/auth protected 'auth:api' middleware authorization header bearer eyjpdii6iklonfqrc1y2def3mhjtou1qwwvndwc9psisinzhbhvlijoiz1h6... the bearer token generated using createtoken function , being correctly passed through. yet, receive unauthorized response.
using lumen , lumen-passport package.
Comments
Post a Comment