Add OIDC Socialite driver with configuration and provider tests
This commit is contained in:
parent
0c4e7d22eb
commit
b8e5995c73
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user