Machine to Machine Laravel Passport

Posted: 2017-06-02 19:31:15

Recently I needed to create an OAuth around Machine to Machine authentication here

The docs are good but I must have missed something obvious or maybe I just well missed something obvious.

Basically I just kept getting Unauthenticated. and this makes sense since I received the token using


So after following the docs I had to then to the following

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request;


Route::middleware('auth.client')->get('/user', function (Request $request) {
    return "FOO";

'auth.client' being key!

And updated app/Http/Kernel.php:

    protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'auth.client' => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,

Adding auth.client then I was back in business.