-
-
Notifications
You must be signed in to change notification settings - Fork 398
Using Swagger UI with Passport
Darius Matulionis edited this page Sep 11, 2020
·
1 revision
The easiest way to build and test your Laravel-based API using Swagger-php is to use Passport's CreateFreshApiToken
middleware. This middleware, built into Laravel's core, adds a cookie to all responses, and the cookie authenticates all subsequent requests through Passport's TokenGuard
.
To get started, first publish L5-Swagger's config and view files into your own project:
$ php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
Next, edit your config/l5-swagger.php
configuration file. Locate the l5-swagger.defaults.routes.middleware
section, and add the following middleware list to the api
route:
'api' => [
\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,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
'auth',
]