laravel - Testing with 'auth:api' middleware enabled -


i working on testing api endpoints. api middleware grouped following:

'api' => [     'throttles:1,60',     'bindings',     'auth:api' ]; 

i have jwt cookie token submitting correctly front-end when accessing api endpoints; works fine. how validate oauth token when i'm sending requests test classes? getting requests redirected login page.

i've tried using 5.2 , below method of $this->actingas($user) doesn't buy me correct level of auth.

i've tried using withoutmiddleware trait, in turn disabled route model binding.

here's workaround right now:

first, created new $middlewaregroup entry in app\http\kernel.php doesn't include auth:api rule.

'api-testing' => [         'throttle:60,1',         'bindings',     ], 

and added logic behind routeserviceprovider's method mapapiroutes().

protected function mapapiroutes() {     // use 'api-testing' middleware during testing     $middleware = 'api';     if (env('app_env') === 'testing') {         $middleware .= '-testing';     }      route::group([         'middleware' => $middleware,         'namespace' => $this->namespace,         'prefix' => 'api/v1',     ], function ($router) {         require base_path('routes/api.php');     }); } 


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -