Laravel Passport客户端凭据授予类型用户模型

时间:2019-08-26 08:05:53

标签: client credentials laravel-passport

我想将我的User模型的accessToken与Client Credentials Grant一​​起使用来确定特定路由。

有可能吗?如果没有,正确的方法是什么?

即使有文档,我也无法知道这是否可能。

错误日志

Illuminate\Auth\AuthenticationException : Unauthenticated. 
vendor/laravel/passport/src/Http/Middleware/CheckClientCredentials.php:48

kernel.php

/**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \App\Http\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'client' => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
        'optimizeImages' => \Spatie\LaravelImageOptimizer\Middlewares\OptimizeImages::class,
        'userAgency' => \App\Http\Middleware\UserAgency::class,
        'guard' => \App\Http\Middleware\SetGuard::class,
    ];

RouteServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapWebRoutes();
        $this->mapApiRoutes();
        $this->mapClientRoutes();
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')->namespace($this->namespace)->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::namespace($this->namespace)->group(base_path('routes/api.php'));
        Route::middleware(['auth:api'])->namespace($this->namespace)->prefix('api')->group(base_path('routes/common.php'));
    }

    /**
     * Define the "api" routes for the client.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapClientRoutes()
    {
        Route::namespace($this->namespace)->group(base_path('routes/api.php'));
        Route::middleware(['client'])->namespace($this->namespace)->prefix('api')->group(base_path('routes/common.php'));
    }
}

预先感谢您的回答。

0 个答案:

没有答案