Closed bim-and-more-inikolov closed 4 years ago
You can use the data retrieved by Keycloak to create a user.
And you can implement your own user model: https://github.com/Vizir/laravel-keycloak-web-guard#how-to-implement-my-model
Dear Mario,
Thanks for the fast answer. I already created my own model. My question is more about where in the code I should save the user? Is it in the constructor of my new User model?
Thanks in advance!
There is no hook on Guard to do it. :(
You can do it in user construct... maybe (or in controller). But I'm not sure it is the best place, because will save every request...
Maybe a better solution is:
1 - In config leave "callback" route empty.
This way it will not be registered here.
2 - Next register your own route.
This way:
// Should be on middleware web and keep this name
Route::get('callback', 'YourController@callback')->name('keycloak.callback');
3 - Process the callback.
This controller should extend Illuminate\Routing\Controller
and implemente the callback method from Vizir\KeycloakWebGuard\Controllers\AuthController
(check here).
4 - Now you can save User after login callback
On callback, right before redirect to intended page.
On previous step, you can extend the AuthController and call parent callback saving the response. It's better because you'll get the changes from our controller (we have nothing planned for this, but maybe...).
After that, check user is setted, save and return parent response.
Remember: you can get tokens and profile using KeycloakService or the facade:
use Vizir\KeycloakWebGuard\Facades\KeycloakWeb;
I hope this help you :)
Hey @bim-and-more-inikolov . It did work?
Closing due to inactivity.
check my solution #32
Hello,
How can I save the Model when the user is authenticated to the database?
Thank you in advance!
Best, Ivan