middleware

Laravel middleware returning (Trying to get property 'headers' of non-object) error

ⅰ亾dé卋堺 提交于 2020-05-29 18:06:20
问题 I'm getting error when I wrap a resource route to my custom middleware My middleware : <?php namespace App\Http\Middleware; use Closure; use Auth; class Officer { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Auth::check() && Auth::user()->role == 'title_officer') { return $next($request); } // elseif (Auth::check() && Auth::user()->role == 'agent') { // return

Jest Express testing middleware with arguments

主宰稳场 提交于 2020-05-17 07:25:17
问题 I'm pretty new to node and this is my first time unit testing an app. I'm doing well with Jest faking the request with Jest function as below // Create a fake request const mockRequest = (sessionData, body) => ({ session: { data: sessionData }, body }); // Create a fake response const mockResponse = () => { const res = {}; res.status = jest.fn().mockReturnValue(res); res.json = jest.fn().mockReturnValue(res); return res; }; const mockNext = () => { const next = jest.fn(); return next; }; So I

Route Middleware in Slim 4 doesn't stop invoking the callable in the route

守給你的承諾、 提交于 2020-04-30 06:31:26
问题 I'm strugling with authorization middleware in Slim4. Here's my code: $app = AppFactory::create(); $app->add(new Authentication()); $app->group('/providers', function(RouteCollectorProxy $group){ $group->get('/', 'Project\Controller\ProviderController:get'); })->add(new SuperuserAuthorization()); Authentication middleware checks the user and works fine. The method get in ProviderController is public function get(Request $request, Response $response): Response{ $payload = []; foreach(Provider:

Adding 'SameSite=None;' cookies to Rails via Rack middleware?

别等时光非礼了梦想. 提交于 2020-04-13 03:59:49
问题 On February 4th 2020, Google Chrome will require SameSite=None; to be added to all cross-site cookies. Rails 6.1 and soon Rails 6.0 have added a same_site: :none option to the rails cookie hash: cookies["foo"]= { value: "bar", expires: 1.year.from_now, same_site: :none } But older Rails 5.x apps won't receive the upgrade to have access to the same_site options hash. I know the SameSite=None; cookie option can be manually added to Rails in a controller using: response.headers["Set-Cookie"] =

wrap-cors middleware not working with system.components

[亡魂溺海] 提交于 2020-03-25 21:51:22
问题 I have the following system.components middleware config, in which I'm using the ring.middleware wrap-cors, to allow for redirects to an external server: (defn config [] {:http-port (Integer. (or (env :port) 5000)) :middleware [[wrap-defaults api-defaults] wrap-with-logger wrap-gzip ignore-trailing-slash [wrap-reload {:dir "../../src"}] [wrap-trace :header :ui] wrap-params wrap-keyword-params wrap-cookies [wrap-cors :access-control-allow-headers #{"accept" "accept-encoding" "accept-language"

Laravel 5 : passing a Model parameter to the middleware

此生再无相见时 提交于 2020-03-23 04:28:09
问题 I would like to pass a model parameter to a middleware. According to this link (laravel 5 middleware parameters) , I can just include an extra parameter in the handle() function like so : public function handle($request, Closure $next, $model) { //perform actions } How would you pass it in the constructor of the Controller? This isn't working : public function __construct(){ $model = new Model(); $this->middleware('myCustomMW', $model); } **NOTE : ** it is important that I could pass

Laravel 5 : passing a Model parameter to the middleware

依然范特西╮ 提交于 2020-03-23 04:28:06
问题 I would like to pass a model parameter to a middleware. According to this link (laravel 5 middleware parameters) , I can just include an extra parameter in the handle() function like so : public function handle($request, Closure $next, $model) { //perform actions } How would you pass it in the constructor of the Controller? This isn't working : public function __construct(){ $model = new Model(); $this->middleware('myCustomMW', $model); } **NOTE : ** it is important that I could pass

ASP .NET Core webapi set cookie in middleware

偶尔善良 提交于 2020-02-25 04:13:33
问题 I'm trying to set a cookie after the action is executed, struggling to get this working. I managed to see the cookie if I set it from a controller, but not from a middleware. I have played with the order of the configuration and nothing. The code sample is from a clean webapi created project, so if someone wants to play with it is simple, just create an empty webapi, add the CookieSet class and replace the Startup class with the one below (only added are the cookie policy options) Here is my

Route Middleware in Slim 4 doesn't stop invoking the callable in the route

青春壹個敷衍的年華 提交于 2020-02-15 08:05:28
问题 I'm strugling with authorization middleware in Slim4. Here's my code: $app = AppFactory::create(); $app->add(new Authentication()); $app->group('/providers', function(RouteCollectorProxy $group){ $group->get('/', 'Project\Controller\ProviderController:get'); })->add(new SuperuserAuthorization()); Authentication middleware checks the user and works fine. The method get in ProviderController is public function get(Request $request, Response $response): Response{ $payload = []; foreach(Provider:

How to redirect to Blazor with token

自作多情 提交于 2020-02-02 13:14:20
问题 I have a Middleware which performs an authentification and should then reroute to a Blazor web application. The problem is that I get the token put in the request query and I want it in the body of the request. Middleware: public async Task Invoke(HttpContext context) { string token = context.Request.Query["token"]; if (!context.User.Identity.IsAuthenticated) { //do some logic to authenticate } else await this.next(context); } Configure: public void Configure(IApplicationBuilder app,