Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF token mismatch error #543

Open
guigralho opened this issue May 26, 2023 · 6 comments
Open

CSRF token mismatch error #543

guigralho opened this issue May 26, 2023 · 6 comments

Comments

@guigralho
Copy link

  • L5-Swagger Version: 8.5.0
  • PHP Version (php -v): 8.2.6
  • OS: ubuntu 22

When I make requests via the swagger documentation, the X-CSRF-TOKEN on header is null all the times and I get the SRF token mismatch error

Captura de tela de 2023-05-26 13-43-26

@lpovkhan
Copy link

lpovkhan commented Jun 5, 2023

Looks like documentation routes need middleware "web"
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
and in config/l5-swagger.php:
defaults-> middleware[
'api' => ['web'],
'asset' => [],
'docs' => [],
'oauth2_callback' => [],
]

@OsamaAlmamri
Copy link

OsamaAlmamri commented Sep 30, 2023

in kernel file section api
commit this middleare \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,

    'api' => [
     // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        \Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

@quanghuybest2k2
Copy link

Fixed this issue by updating file app/Http/Middleware/VerifyCsrfToken.php

Add /api/* item to $except array:

protected $except = [
  "/api/*"
];

@vibonacci
Copy link

@quanghuybest2k2
You're disabling the CRSF checks for all API routes. That is NOT recommended. CSRF tokens are important if API calls are made from browser/web.

@JacksonPorter7478
Copy link

  • L5-Swagger Version: 8.5.0
    -PHP Version (php -v): 8.2.12
    -OS: windows
    -laravel/framework: 9.52.16

I have same errors.
I try to fix that error according to your tips but I can't fix that error and I have same so.

Screenshot 2024-01-14 153950

@marcelodmdo
Copy link

Looks like documentation routes need middleware "web" php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" and in config/l5-swagger.php: defaults-> middleware[ 'api' => ['web'], 'asset' => [], 'docs' => [], 'oauth2_callback' => [], ]

This works like charm. Looks the right and safe way. That's right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants