Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TokenMismatchException for API in Laravel 5.2.31

What Am I trying?

I already have a website and I am trying Token based authentication for an API in same code and below is the start for sample authentication code

I created a controller below is the code.

class AccountController extends \App\Http\Controllers\Controller
{
    public function apilogin($UserData) {
        return json_decode($UserData);
    }
}

My route config is below.

Route::group(['prefix' => 'api/v1', 'middleware' => 'auth.api'], function () {
    Route::post('/apilogin', 'API\User\Account\AccountController@apilogin');
});

**Then from the Postman Chrome Extension, I have posted the request and worked fine if I comment the following line from $middlewareGroups in Kernel.php

\App\Http\Middleware\VerifyCsrfToken::class,

I have no issues VerifyCsrfToken if I do GET request from POSTMan Extension

like image 758
Pankaj Avatar asked May 23 '16 05:05

Pankaj


1 Answers

Open your app\http\Middleware\VerifyCsrfToken.php file.

Here edit $except property with:

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

This will exclude your api routes from CSRF verification.

like image 121
Abhishek Avatar answered Oct 22 '22 18:10

Abhishek