Keycloak Integration (Using SocialiteProviders) with Laravel 11 error; Class LaravelSocialiteTwoUser contains 7 abstract methods and must theref

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;

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?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
}
}
</code>
<code><?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 } } </code>
<?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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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');
});
</code>
<code>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'); }); </code>
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

New contributor

Asry Robinson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật