Skip to content

Commit

Permalink
Merge pull request #2 from milkmeowo/feature-support-passport
Browse files Browse the repository at this point in the history
Passport Support For Dingo Api
  • Loading branch information
libern authored Nov 17, 2016
2 parents 41d14d0 + 11c9f6d commit 699c8d2
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/Someline/Api/Auth/Provider/Passport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Created for someline-starter.
* User: Milkmeowo
*/

namespace Someline\Api\Auth\Provider;

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 Passport extends Authorization
{

/**
* Illuminate authentication manager.
*
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;

/**
* The guard driver name.
*
* @var string
*/
protected $guard = 'api';

/**
* Create a new basic provider instance.
*
* @param \Illuminate\Auth\AuthManager $auth
*/
public function __construct(AuthManager $auth)
{
$this->auth = $auth->guard($this->guard);
}

/**
* Authenticate request with a Illuminate Guard.
*
* @param \Illuminate\Http\Request $request
* @param \Dingo\Api\Routing\Route $route
*
* @return mixed
*/
public function authenticate(Request $request, Route $route)
{
if ( ! $user = $this->auth->user()) {
throw new UnauthorizedHttpException(null, 'Unauthenticated.');
}

return $user;
}

/**
* Get the providers authorization method.
*
* @return string
*/
public function getAuthorizationMethod()
{
return 'Bearer';
}
}


0 comments on commit 699c8d2

Please sign in to comment.