vendredi 4 août 2017

Laravel 5.4 401/Unauthenticated using passport and personal access tokens

The backstory on this, I have been working on the instructions from the documentation: http://ift.tt/2lZ4c5M

I have

  1. Laravel 5.4
  2. "laravel/passport": "^3.0" from composer
  3. Local Mac osx running Mamp pro, Php 7.0.15

Postman curl Header (pulled from the code export in Postman):

CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImM3ZmI2ZmNmMWFkOGQ0NjFkNTdhMWU2NjFiYjhhOThmOTJhOTBkMDFkNDkwZDFjNDRkNDg5MTdlYjJiZWYyMDlkNjNmOTQwMjIxNTljZWI5In0.eyJhdWQiOiIxIiwianRpIjoiYzdmYjZmY2YxYWQ4ZDQ2MWQ1N2ExZTY2MWJiOGE5OGY5MmE5MGQwMWQ0OTBkMWM0NGQ0ODkxN2ViMmJlZjIwOWQ2M2Y5NDAyMjE1OWNlYjkiLCJpYXQiOjE1MDE3OTQ2NjIsIm5iZiI6MTUwMTc5NDY2MiwiZXhwIjoxNTMzMzMwNjYyLCJzdWIiOiIxIiwic2NvcGVzIjpbImFwaS1hY2Nlc3MiXX0.CPGM4PIKJBeiJvokuDzShz_1CnqHlnFIML-tWoBCn5GcijMXmQkWOHzTI8QwTws2h719TGA4hemXDljjqoZB0LiztAx2JZ3OhjNS-MhrMNujnTJUbvkXAVfcRdybhlDEWof_iboLICQTYNTslX1iw-2DCyFMh8gB4INAKUhpvzA955ALB-ZunKrjSNKdRkgtZRe0t6VyJf9LwzgjIAfSKoi_qRis36KD7hcf0Id_iWZkhvS-ZfuM5eUpzUooUe0rb4rkYYEYndlHlY7-uuZPlzmPMpaJTR4AW1CLkaK5Ic7fde1x1kk2duW_Znd9ki2YBP0kw7ifAmg2DaM5r2-0kEx_1iFuCIxE8QJns1aIm3XjWoOApovt7V6-s3yJZK3xlIDCjFI-C59RHiVSabh-hKdX4elvSL9taSQyuramPZPpsne9SUh4KCWul0iHoNjFdFJEut_TUBWyUPtD3J7gg6P97uRS_THDAUHMo2UYVhlnu9PV8SvbvjGj3OeaaH7ZbzWQCYKbqsLZAZ2mnJlFhTMghbaC2s_MND1zlRm7w9btmihxVW714NUbH8UAwSvrtIYYQ0itevZ59TLiAXprjmjkhiFkrhdX4bUje4uNEbLYawkZI-1o82IExW9D8kCYpOWOZdWTCLgmaE2wXcf-DTCV-9vDWRAdX1YmP4JbRsc",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    "postman-token: 2ec7a2c8-3489-812d-4638-ebb7dc62aeb1"
  ),

I have 1 personal access token generated using the Vue Components

I have been battling this issue for 2 days now and have read all the peoples issues with token expiration. So I have checked all that and i am setting the expiration for 1 year and that is reflecting in the db.

My AuthServiceProvider.php

Passport::routes();

        // TODO MAKE THEM LAST A LONG TIME
        Passport::tokensExpireIn(Carbon::now()->addYears(20));//You can also use addDays(10)
        Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));//You can also use addDays(10) 
        Passport::pruneRevokedTokens(); //basic garbage collector

        Passport::tokensCan([
            'api-access' => 'Access Complete API',
        ]);

My RouteServiceProvider.php (mapApiRoutes is called in the map function)

protected function mapApiRoutes()
    {
        Route::group([
            'middleware' => 'auth:api',
            'namespace' => $this->namespace,
            'prefix' => 'api',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

My Kernel.php

/**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \App\Http\Middleware\LogLastUserActivity::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            ],
        'client.create' => [ \App\Http\Middleware\Client\CanClientCreate::class ],
        'client.update' => [ \App\Http\Middleware\Client\CanClientUpdate::class ],
        'user.create' => [ \App\Http\Middleware\User\CanUserCreate::class ],
        'user.update' => [ \App\Http\Middleware\User\CanUserUpdate::class ],
        'task.create' => [ \App\Http\Middleware\Task\CanTaskCreate::class ],
        'task.update.status' => [ \App\Http\Middleware\Task\CanTaskUpdateStatus::class ],
        'task.assigned' => [ \App\Http\Middleware\Task\IsTaskAssigned::class ],
        'lead.create' => [ \App\Http\Middleware\Lead\CanLeadCreate::class ],
        'lead.assigned' => [ \App\Http\Middleware\Lead\IsLeadAssigned::class ],
        'lead.update.status' => [ \App\Http\Middleware\Lead\CanLeadUpdateStatus::class ],
        'user.is.admin' => [ \App\Http\Middleware\RedirectIfNotAdmin::class ],
        'api' => [
            'throttle:60,1',
            'bindings',
            'auth:api',
        ],
    ];

And I am trying to access the simple test url provided by Passport:

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

If I pull the 'middleware' => 'auth:api', from the RouteServiceProvider.php I get the response just fine. So somehow my middleware is breaking this.

Any insight is greatly appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2uaMFwZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire