Created
May 25, 2017 12:47
-
-
Save joselfonseca/6db6a167d6bbd410199cce4c7e69be47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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