robsontenorio / laravel-keycloak-guard

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

Feature: sync API users table with autenticated token #44

Closed frital closed 3 years ago

frital commented 3 years ago

This PR aims to, as an option, allow the API to create / update the authenticated user in the the user table. to achieve this this, new configuration parameters were defined, and adjustment was made in KeycloakGuard class.

frital commented 3 years ago

It will close this PR, because it makes not sense like i was thinking to do. I will just create my own User Provider, extending EloquentUserProvider and adjusting the retrieveByCredentials method, in way that it not just try to load from the database, but also create / update if not found ... thx!! =)

robsontenorio commented 3 years ago

Thanks for this. Yes , i agree. There are many custom logic for each app use case.

frital commented 3 years ago

Hi @robsontenorio, thx for you feedback.

But in any case, in order to make a synchronization with the local database possible, it would be necessary to have access to the decoded token within the UserProvider, would you agree? (in order to perform mappings and read other information from the token ... and so on).

Do you think it would be valid to include a configuration key, default as null, obviously, that would define a custom method in a custom UserProvider?

For example, in config\keycloak.php, something like this: 'user_provider_custom_retrieve_method' => 'syncAndRetrieveByToken'

Then the guard will call this method, instead of retrieveByCredentials` passing as argument the decoded token. What do you think of the idea? If you agree, i maked a new PR

Thx in advance!