Skip to content
Advertisement

laravel authorizeResource always denies access

I have created a resource controller for an API endpoint. I have also created a corresponding policy for the model.

If I do a per method authorization check using

JavaScript

then it works as expected. But if I add the following to the construct, I always get a 403 forbidden. Not sure what I am missing as the following should apply the authorization for all methods.

JavaScript

This is what my route looks like:

JavaScript

My policy is registered like this:

JavaScript

My policy method for deleting is

JavaScript

The API controller constructor looks like this:

JavaScript

The API controller method is

JavaScript

And my routes are

JavaScript

I guess I am missing something but I can’t see it, the gate is being shown as denied in Telescope. the only strange thing is that the serveNova middleware seems to be the source of the issue.

Time May 8th 2019, 10:51:37 AM (14m ago)
Hostname core-hosp
Ability delete
Result denied
Location /home/vagrant/code/nova/src/Http/Middleware/ServeNova.php:25
Request View Request
Tags Auth:1

Advertisement

Answer

I’ve described my lessons learn with this tiring problem here: https://github.com/laravel/framework/issues/22847#issuecomment-521308861. Maybe somebody will find it useful.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement