An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(auth): store OIDC raw claims as arrays
Andras Bacsaic656892738d4
diff --git a/app/Services/Auth/OauthLoginService.php b/app/Services/Auth/OauthLoginService.phpindex b0c47a3958..f1c3b4d827 100644--- a/app/Services/Auth/OauthLoginService.php+++ b/app/Services/Auth/OauthLoginService.php@@ -66,7 +66,9 @@ class OauthLoginServicethrow new HttpException(403, 'OIDC provider did not verify the email address');}- return DB::transaction(function () use ($oauthUser, $oauthSetting, $email, $issuer, $subject, $emailVerified) {+ $rawClaims = is_array($oauthUser->user ?? null) ? $oauthUser->user : [];++ return DB::transaction(function () use ($oauthUser, $oauthSetting, $email, $issuer, $subject, $emailVerified, $rawClaims) {$identity = OauthIdentity::where(['provider' => 'oidc','issuer' => $issuer,@@ -76,7 +78,7 @@ class OauthLoginServiceif ($identity) {$identity->update(['email' => $email,- 'raw_claims' => $oauthUser->user,+ 'raw_claims' => $rawClaims,'last_login_at' => now(),]);@@ -107,7 +109,7 @@ class OauthLoginService'issuer' => $issuer,'provider_user_id' => $subject,'email' => $email,- 'raw_claims' => $oauthUser->user,+ 'raw_claims' => $rawClaims,'last_login_at' => now(),]);diff --git a/tests/Feature/OidcOauthControllerTest.php b/tests/Feature/OidcOauthControllerTest.phpindex 6851ba97a2..6ea861ec1f 100644--- a/tests/Feature/OidcOauthControllerTest.php+++ b/tests/Feature/OidcOauthControllerTest.php@@ -131,6 +131,43 @@ it('creates the root user when oidc provisions the first account', function () {expect(InstanceSettings::find(0)->is_registration_enabled)->toBeFalse();});+it('persists raw claims as an array on the oauth identity', function () {+ OauthSetting::where('provider', 'oidc')->update(['allow_registration' => true]);++ fakeOidcProvider(['email' => '[email protected]']);++ $this->get(route('auth.callback', 'oidc'))->assertRedirect('/');++ $identity = OauthIdentity::where('email', '[email protected]')->first();+ expect($identity->raw_claims)->toBeArray()+ ->and($identity->raw_claims['sub'])->toBe('okta-user-1');+});++it('stores empty raw claims when the provider returns no user payload', function () {+ OauthSetting::where('provider', 'oidc')->update(['allow_registration' => true]);++ $user = (new OidcUser)->setIdTokenClaims([+ 'iss' => 'https://idp.example.com',+ 'sub' => 'okta-no-payload',+ 'email_verified' => true,+ ])->map([+ 'id' => 'okta-no-payload',+ 'name' => 'No Payload',+ 'email' => '[email protected]',+ ]);+ $user->user = null;++ $provider = Mockery::mock();+ $provider->shouldReceive('setConfig')->andReturnSelf();+ $provider->shouldReceive('user')->andReturn($user);+ Socialite::shouldReceive('driver')->with('oidc')->andReturn($provider);++ $this->get(route('auth.callback', 'oidc'))->assertRedirect('/');++ $identity = OauthIdentity::where('email', '[email protected]')->first();+ expect($identity->raw_claims)->toBe([]);+});+it('rejects callbacks for disabled oidc provider', function () {OauthSetting::where('provider', 'oidc')->update(['enabled' => false]);diff --git a/tests/Unit/OidcTokenValidatorTest.php b/tests/Unit/OidcTokenValidatorTest.phpindex 3ca021de50..9b1d9a24c3 100644--- a/tests/Unit/OidcTokenValidatorTest.php+++ b/tests/Unit/OidcTokenValidatorTest.php@@ -108,6 +108,7 @@ it('rejects invalid token claims', function (array $claimOverrides, string $mess})->throws(OidcTokenException::class)->with(['issuer mismatch' => [['iss' => 'https://evil.example.com'], 'issuer'],'audience mismatch' => [['aud' => 'other-client'], 'audience'],+ 'azp missing for multi audience' => [['aud' => ['client-id', 'other-client']], 'azp'],'azp mismatch' => [['aud' => ['client-id', 'other-client'], 'azp' => 'other-client'], 'azp'],'expired token' => [['exp' => time() - 3600], 'expired'],'future issued at' => [['iat' => time() + 3600], 'issued'],