mariovalney / laravel-keycloak-web-guard

Simple Keycloak Guard to Laravel Web Routes - https://packagist.org/packages/vizir/laravel-keycloak-web-guard
146 stars 80 forks source link

Problem In Keycloak Web Gate #52

Closed viveksudalai closed 3 years ago

viveksudalai commented 3 years ago

Hi, I am using Laravel and Vue.Js. Login and redirection is working fine. But i am getting following error when i try to use "abort_if(Gate::denies('keycloak-web','Client Admin'), Response::HTTP_FORBIDDEN, '403 Forbidden') " in my controller. 'Client Admin' is the Keycloak client Role.

message | "Argument 1 passed to Spatie\Permission\PermissionRegistrar::Spatie\Permission\{closure}() must be an instance of Illuminate\Contracts\Auth\Access\Authorizable, instance of Vizir\KeycloakWebGuard\Models\KeycloakUser given, called in /opt/lampp/htdocs/XXXweb/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 495"

exception | "TypeError" file | "/opt/lampp/htdocs/XXXweb/vendor/spatie/laravel-permission/src/PermissionRegistrar.php"

And also i have role and their permission in my application. I want to use my application permission instead of keycloak resoureces.

auth.php

guards' => [ 'web' => [ 'driver' => 'keycloak-web', 'provider' => 'keycloak-users', ],

    'api' => [
        'driver' => 'keycloak-web',
        'provider' => 'keycloak-users',
        'hash'     => false,
    ],

'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'keycloak-users' => [ 'driver' => 'keycloak-users', 'model' => Vizir\KeycloakWebGuard\Models\KeycloakUser::class, ], ],

viveksudalai commented 3 years ago

Would you please help me to resolve this?

mariovalney commented 3 years ago

Hi!

Sounds like our default model is not compatible with spatie/laravel-permission.

Said that, I'm not sure you should use spatie/laravel-permission as it is used to manage roles and permissions: Keycloak is already able to do that.

Anyway, here is how to implement User as a Eloquent Model:

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.