Add OIDC Socialite driver with configuration and provider tests
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
= 2026-06-17 07:17:05 +00:00
parent 0c4e7d22eb
commit b8e5995c73
4 changed files with 19 additions and 8 deletions

View File

@ -16,11 +16,11 @@ class AuthenticateOidcUser
public function execute(OidcUserData $data): User
{
// Search by subject claim
$user = User::where('oidc_sub', $data->sub)->first();
$user = User::query()->where('oidc_sub', $data->sub)->first();
if (! $user) {
// Fallback: search by email to map existing accounts
$user = User::where('email', $data->email)->first();
$user = User::query()->where('email', $data->email)->first();
if ($user) {
// Link account

View File

@ -7,7 +7,6 @@
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
use Symfony\Component\HttpFoundation\Response;
class OidcController extends Controller

View File

@ -28,9 +28,10 @@ public function boot(): void
{
$this->configureDefaults();
Event::listen(function (SocialiteWasCalled $event) {
$event->extendSocialite('oidc', OIDCExtendSocialite::class);
});
Event::listen(
SocialiteWasCalled::class,
OIDCExtendSocialite::class
);
}
/**

View File

@ -3,10 +3,21 @@
use App\Models\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\User as SocialiteUser;
use SocialiteProviders\OIDC\Provider;
beforeEach(function () {
// Clear oidc services config to mock config checks
config(['services.oidc.client_id' => 'mock_client_id']);
// Mock oidc services config
config([
'services.oidc.client_id' => 'mock_client_id',
'services.oidc.client_secret' => 'mock_client_secret',
'services.oidc.redirect' => 'https://mock-app.com/auth/oidc/callback',
'services.oidc.base_url' => 'https://mock-oidc-provider.com',
]);
});
test('oidc socialite driver resolves to the correct provider class', function () {
$driver = Socialite::driver('oidc');
expect($driver)->toBeInstanceOf(Provider::class);
});
test('oidc login button is visible on login page when configured', function () {