Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save joselfonseca/6db6a167d6bbd410199cce4c7e69be47 to your computer and use it in GitHub Desktop.

Select an option

Save joselfonseca/6db6a167d6bbd410199cce4c7e69be47 to your computer and use it in GitHub Desktop.
<?php
namespace Joselfonseca\LaravelApiTools\Auth;
use Illuminate\Http\Request;
use Dingo\Api\Routing\Route;
use Dingo\Api\Auth\Provider\Authorization;
use Illuminate\Contracts\Auth\Factory as Auth;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
/**
* Class PassportAuthenticationProvider
* @package App\Auth
*/
class PassportAuthenticationProvider implements \Dingo\Api\Contract\Auth\Provider
{
/**
* @var Auth
*/
protected $auth;
/**
* PassportAuthenticationProvider constructor.
* @param Auth $auth
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* @param Request $request
* @param Route $route
* @return mixed
*/
public function authenticate(Request $request, Route $route)
{
if ($this->auth->guard('api')->check()) {
$this->auth->shouldUse('api');
return $this->auth->guard('api')->user();
}
throw new UnauthorizedHttpException('Unable to authenticate.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment