Hey, I was wondering if you did already have a look at passport and if there are any plans use it.
As far as I understand dingo would still provide some benefits on top of passport, like the whole transformer (fractal) part, etc.
So maybe you could use passport so that you do not have to deal with the integration of oAuth2 Server into Laravel / Lumen?
What is passport? (other than the document used to travel through countries)
A just released (Preview) Implementation of an oAuth 2 Server by Taylor Ottwell. It is build on top of the league oAuth Server package, just like dingo and of course should integrate well with Laravel and lumen.
@lukasoppermann Thats something I thought of as well. Gonna aim for getting a version 1.0.0 released first, and then work for 5.3 support. Will probably aim to include passport with the 5.3 support.
Now that #1152 has been merged adding 5.3 support, will look into Passport. No promises of getting added for version 1.0.0 though
I've added a pretty basic auth provider to use Laravel's Passport, it gathers the user from the request due Passport authorizes and append the user to the current request, all the exceptions are trown via Passport, it seems to work, here is what I've done:
_App/Providers/PassportDingoProvider.php_
<?php namespace App\Providers;
use Dingo\Api\Auth\Provider\Authorization;
class PassportDingoProvider extends Authorization
{
public function authenticate(Request $request, Route $route)
{
return $request->user();
}
public function getAuthorizationMethod()
{
return 'bearer';
}
}
_config/api.php_
...
/*
|--------------------------------------------------------------------------
| Authentication Providers
|--------------------------------------------------------------------------
|
| The authentication providers that should be used when attempting to
| authenticate an incoming API request.
|
*/
'auth' => [
'custom' => \App\Providers\PassportDingoProvider::class
],
...
_App/Http/Kernel.php_
...
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
...
'api:auth' =>
[
'auth:api',
'api.auth'
]
...
];
...
_routes/api.php_
...
$api->group(['middleware' => 'api:auth'], function($api){
...
});
...
Maybe is not the ideal solution but it works so far for me right now, I'm still looking for another decoupled solution to handle Passport authorization via Dingo and not from the framework itself.
What about dusterio/lumen-passport ?
@samuelcasas @hskrasek
Archive GuardServiceProvider.php in App\Providers
<?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 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(
get_class($this),
'Unable to authenticate with invalid API key and token.'
);
}
return $user;
}
/**
* Get the providers authorization method.
*
* @return string
*/
public function getAuthorizationMethod()
{
return 'Bearer';
}
}
config\api.php
'auth' => [
'Guard' => \App\Providers\GuardServiceProvider::class
],
Hey,
I know this thread is old, but I also had to migrate to Passport and I managed to get it to work with almost the exact way as the original OAuth provider.
In case anyone is interested the gist is here .
The only "big" change I had to make was to pass whole Token object to user and client resolvers.
@realshadow I think there's missing class in your Gist (LoginService)
@hnq90 That is my just my custom service for logging in users. You can put whatever you like in the user resolver just like in the original OAuth implementation
Can someone confirm #1236? Has anyone tested?
@pedroskakum works for me 馃憤
Most helpful comment
I've added a pretty basic auth provider to use Laravel's Passport, it gathers the user from the request due Passport authorizes and append the user to the current request, all the exceptions are trown via Passport, it seems to work, here is what I've done:
_App/Providers/PassportDingoProvider.php_
_config/api.php_
_App/Http/Kernel.php_
_routes/api.php_
Maybe is not the ideal solution but it works so far for me right now, I'm still looking for another decoupled solution to handle Passport authorization via Dingo and not from the framework itself.