Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
297 stars 18 forks source link

Authorizations allways return unauthorized action #87

Closed dardarwail closed 6 months ago

dardarwail commented 6 months ago

Laravel Rest Api Version

2.3

Laravel Version

10.10

PHP Version

8.3

Database Driver & Version

No response

Description

Even if I add a UserPolicy file and return true in all methods (such as view and viewAny), I still receive the 'This action is unauthorized' message. I can't figure out if this is a bug or if I am doing something wrong! According to the documentation, I just need to associate my model with the policy.

Steps To Reproduce

  1. Generating Policies
  2. Registering Policies in AuthServiceProvider
GautierDele commented 6 months ago

Hello, could you please try using the "DisableAuthorizations" on your resource to verify it's policies related ?

If it's working well with this trait, the problem might be related with your configuration. You could try debugging using tinker mostly 😄

Otherwise, please give me some details as I have tests running for this I might be missing something

dardarwail commented 6 months ago

Hello, Oops, my bad!

I forgot an important note:

By default, all gates and policies automatically return false if the incoming HTTP request was not initiated by an authenticated user.

Thanks a lot!

GautierDele commented 6 months ago

So the problem is not package related ?

Please have a look at Laravel Policies: https://laravel.com/docs/10.x/authorization#guest-users

dardarwail commented 6 months ago

No Not related to the package Thanks