dusterio / lumen-passport

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

POST on route /oauth/token gives 405 Method Not Allowed exception #70

Closed tsperling closed 6 years ago

tsperling commented 6 years ago

Similar issue to some already posted, but slightly different in that, having followed the setup guide, all oauth routes are working ok (resulting in an 'Unauthorized.' message when no parameters are passed), except for the POST /oauth/token route, which gives the standard Laravel 405 error page.

This is on a new installation of Lumen 5.6, using latest version of lumen-passport. Tested using Postman.

I've tried the different methods, but all give the same result. Including the required parameters with the request has no effect.

dusterio commented 6 years ago

Do you have an exception stack from storage/logs/laravel.log? Could you post it here please?

dusterio commented 6 years ago

There seems to be a bug in Laravel Passport that causes this, but I found a workaround, try putting this in any SP of yours:

    $this->app->singleton(\Illuminate\Hashing\HashManager::class, function ($app) {
        return new \Illuminate\Hashing\HashManager($app);
    });
tsperling commented 6 years ago

Hi, thanks for the help - unfortunately, I'm still having this problem. Code was added to the register() method of AppServiceProvider, which is uncommented in bootstrap/app.php

There's nothing relating to this in the log, it's just being rejected like any invalid route.

dusterio commented 6 years ago

@tsperling did you register the routes?

Dusterio\LumenPassport\LumenPassport::routes($this->app);

tsperling commented 6 years ago

Yes, that's in place - AppServiceProvider.php looks like this:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        \Dusterio\LumenPassport\LumenPassport::routes($this->app);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        $this->app->singleton(\Illuminate\Hashing\HashManager::class, function ($app) {
                return new \Illuminate\Hashing\HashManager($app);
        });

    }
}
tsperling commented 6 years ago

Looks like this was a combination of the Passport bug and user error - restarted with the latest version of lumen-passport & correctly using HTTPS requests, POST requests are now working correctly. Many thanks :)