robsontenorio / laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel
MIT License
434 stars 141 forks source link

Auth::hasRole(...) => true returns unexpected #32

Closed sascha284 closed 4 years ago

sascha284 commented 4 years ago

Thanks for this great solution! It works realy nice. Just have one problem. I tried: Auth::hasRole('SuperUser') => true and also insert use Illuminate\Contracts\Auth\Guard; But it returned me a syntax error (unexpected '=>' (T_DOUBLE_ARROW). I am also using realm roles. Is Auth::hasRole checking this, too?

robsontenorio commented 4 years ago

It is just a example of return value. Just changed README to avoid confusion.

Auth::hasRole('myapp-backend', 'myapp-backend-role1') // true
Auth::hasRole('myapp-frontend', 'myapp-frontend-role1') // true
Auth::hasRole('myapp-backend', 'myapp-frontend-role1') // false
luizjr commented 1 year ago

@robsontenorio Tudo bom? Espero que sim! Cara esse pacote está me servindo, mas tem uma coisa que me incomoda um pouco nessa funcionalidade.

É complesxo para que funcione com multiplas validações, ex: Usuário tem 'operador' e 'gestor' como papeis definidos no Keycloak.

Auth::hasRole('myapp-backend', 'gestor', 'admin') // true Auth::hasRole('myapp-backend', 'gestor') // true Auth::hasRole('myapp-backend', 'operador', 'admin' ) // true Auth::hasRole('myapp-backend', 'admin' ) // false

Translated

@robsontenorio Everything good? I hope so! Man, this package is serving me, but there is something that bothers me a little about this functionality.

It is complex to work with multiple validations, ex: User has 'operator' and 'manager' as roles defined in Keycloak.

Auth::hasRole('myapp-backend', 'manager', 'admin') // true Auth::hasRole('myapp-backend', 'manager') // true Auth::hasRole('myapp-backend', 'operator', 'admin' ) // true Auth::hasRole('myapp-backend', 'admin' ) // false

robsontenorio commented 1 year ago

@luizjr you are looking for hasAnyRole that not exists. Are you able to send a PR with proper tests?

luizjr commented 1 year ago

I can try, we'll see if I can

luizjr commented 1 year ago

@robsontenorio I just created a pull request to implement this function.

https://github.com/robsontenorio/laravel-keycloak-guard/pull/88

luizjr commented 1 year ago

@robsontenorio I've updated the pull request, I think it should meet expectations well. https://github.com/robsontenorio/laravel-keycloak-guard/pull/88