dusterio / lumen-passport

Making Laravel Passport work with Lumen
MIT License
654 stars 139 forks source link

not support lumen 9 #172

Closed Rasoul-Karimi closed 2 years ago

Rasoul-Karimi commented 2 years ago

hi i have a error on lumen 9

`LumenPassport::routes($this->app, ['prefix' => 'v1/oauth']);

Call to undefined method Laravel\Lumen\Application::group()

`

iriartmaxim commented 2 years ago

i have the same problem.

raulquintana commented 2 years ago

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.".

Rasoul-Karimi commented 2 years ago

@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

raulquintana commented 2 years ago

@Rasoul-Karimi can you check it again?

Rasoul-Karimi commented 2 years ago

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

beeards commented 2 years ago

Closes #172;

WORKS W LUMEN 9 following @raulquintana steps without issue.

* Maybe README.md can be improved.

dusterio commented 2 years ago

@beeards @Rasoul-Karimi @raulquintana can somebody make a PR? :)

Rasoul-Karimi commented 2 years ago

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

beeards commented 2 years ago

@dusterio you got it here #173 👌 with @raulquintana & @Rasoul-Karimi indications.

dusterio commented 2 years ago

@beeards nice one, thanks!

Rasoul-Karimi commented 2 years ago

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

chitos07 commented 2 years ago

error still exist