At the end of so much struggle I could make Passport work with Dingo Api for my Apis-Rest I leave the code if someone needs it and can help and can improve it and make it more efficient and correct
GuardServiceProvider.php file
<?php
/**
* Created by PhpStorm.
* User: vdjke
* Date: 10/28/2016
* Time: 6:31 p.m.
*/
namespace App\Providers;
use Dingo\Api\Routing\Route;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Dingo\Api\Auth\Provider\Authorization;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
/**
* Class GuardServiceProvider
* @package App\Providers
*/
class GuardServiceProvider extends Authorization
{
/**
* @var \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
*/
protected $auth;
/**
* @var string
*/
protected $guard = 'api';
/**
* GuardServiceProvider constructor.
* @param AuthManager $auth
*/
public function __construct(AuthManager $auth)
{
$this->auth = $auth->guard($this->guard);
}
/**
* @param Request $request
* @param Route $route
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function authenticate(Request $request, Route $route)
{
if (! $user = $this->auth->user()) {
throw new UnauthorizedHttpException(
get_class($this),
'Invalid API key and token.'
);
}
return $user;
}
/**
* @return string
*/
public function getAuthorizationMethod()
{
return 'Bearer';
}
}
On your Kernel.php
'api' => [
'auth:api',
'api.auth',
'throttle:60,1',
'bindings',
],
Use of middleware in your route files
$api->group(['middleware' => ['api']], function($api){
$api->get('stream', 'ApiStreamController@index');
});
I hope it serves you something and it will be useful to you