Closed Rasoul-Karimi closed 2 years ago
i have the same problem.
With Lumen (9.0.2) (Laravel Components ^9.0)
composer create-project --prefer-dist laravel/lumen test
cd test
configure your .env
file
composer require dusterio/lumen-passport
composer require laravel/passport
// bootstrap/app.php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
$app->withFacades();
$app->withEloquent();
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->configure('app');
$app->configure('auth');
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});
return $app;
// app/Providers/AuthServiceProvider.php
namespace App\Providers;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Dusterio\LumenPassport\LumenPassport;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
LumenPassport::routes($this->app->router, ['prefix' => 'v1/oauth']);
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
}
}
// app/Models/User.php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use HasApiTokens, Authenticatable, Authorizable, HasFactory;
protected $fillable = [
'name', 'email',
];
protected $hidden = [
'password',
];
}
// config/auth.php
return [
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Models\User::class
]
]
];
php artisan migrate
php artisan passport:install
Then you can visit https://example.test/v1/oauth/tokens. You should see "Unauthorized.".
@raulquintana this is not a true
is issues in file: Dusterio\LumenPassport and LumenPassport.php in lumen version on line 67 and your answer is not ok
@Rasoul-Karimi can you check it again?
this is a difficult way, my friend! :)) this package needs to update and support lumen 9, just this! i don't know where is the admin of this package, and why don't update this repository @dusterio
Closes #172;
✅ WORKS W LUMEN 9 following @raulquintana steps without issue.
* Maybe README.md can be improved.
@beeards @Rasoul-Karimi @raulquintana can somebody make a PR? :)
hi @beeards
please look at to :
Dusterio\LumenPassport and LumenPassport.php in lumen version on line 67 and your answer is not ok
and fix it
@dusterio you got it here #173 👌 with @raulquintana & @Rasoul-Karimi indications.
@beeards nice one, thanks!
please create a tag and version on this commit! this update released on master branch and in composer update is not updated!!!! my God :(( @dusterio @beeards
error still exist
hi i have a error on lumen 9
`LumenPassport::routes($this->app, ['prefix' => 'v1/oauth']);
Call to undefined method Laravel\Lumen\Application::group()
`