Im currently trying to integrate Keycloak to my Laravel 11 application. The plan is to use Keycloak as Authentication Provider for user to login to my system instead of the conventional way of loggin in.
the problem is, i wanted keycloak to handle all the authentication process, and i do not want user table on my apps since i already import all user to my keycloak environment, and planning to make keycloak handle the login process.
however, im getting this error when i try to login to my apps. Im doing this locally on my windows machine. im using socialitekeycloak provider and v11 of laravel.
Class LaravelSocialiteTwoUser contains 7 abstract methods and must therefore be declared abstract or implement the remaining methods (IlluminateContractsAuthAuthenticatable::getAuthIdentifierName, IlluminateContractsAuthAuthenticatable::getAuthIdentifier, IlluminateContractsAuthAuthenticatable::getAuthPasswordName, …)
this is my KeycloakUser model;
<?php
namespace AppModels;
use IlluminateContractsAuthAuthenticatable;
use IlluminateFoundationAuthUser as Authenticatable;
class KeycloakUser extends Authenticatable
{
use HasFactory;
// Add the necessary fields for your user
protected $fillable = [
'keycloak_id', 'name', 'email', 'keycloak_token', 'keycloak_refresh_token',
];
// Implement methods required by the Authenticatable interface
public function getAuthIdentifierName()
{
return 'keycloak_id'; // or 'id' depending on your setup
}
public function getAuthIdentifier()
{
return $this->keycloak_id;
}
public function getAuthPassword()
{
return null; // No password required for Keycloak users
}
public function getRememberToken()
{
return null; // Optional, if you don't need "remember me" functionality
}
public function setRememberToken($value)
{
// Optional, if you don't need "remember me" functionality
}
public function getRememberTokenName()
{
return ''; // Optional, if you don't need "remember me" functionality
}
}
and i design my route like below
Route::get('/', function () {
return redirect('/auth/redirect');
});
Route::get('/auth/redirect', function () {
return Socialite::driver('keycloak')->redirect();
});
Route::get('/auth/callback', function () {
$keycloakUser = Socialite::driver('keycloak')->user();
$user = KeycloakUser::updateOrCreate([
'keycloak_id' => $keycloakUser->id,
], [
'name' => $keycloakUser->name,
'email' => $keycloakUser->email,
'keycloak_token' => $keycloakUser->token,
'keycloak_refresh_token' => $keycloakUser->refreshToken,
]);
Auth::login($user);
return redirect('/dashboard');
});
i dont know what exactly the error means. kindly please help.
Im expecting after user login via keycloak, my app will routed me to /dashboard pages, no error included
Asry Robinson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.