Skip to content

Commit

Permalink
Log error & Check OpenID config to ease SSO setup - See #325
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubka committed Jun 10, 2024
1 parent ef11bef commit d1c2a05
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/Auth/SocialiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;

Expand All @@ -20,10 +21,16 @@ class SocialiteController extends Controller
*/
public function redirect(Request $request, string $driver)
{
// Generic SSO provider definition check
if (! config('services.' . $driver . '.client_id') || ! config('services.' . $driver . '.client_secret')) {
return redirect('/error?err=sso_bad_provider_setup');
}

// OpenID SSO provider definition check
if ($driver == 'openid' && (! config('services.openid.token_url') || ! config('services.openid.authorize_url') || ! config('services.openid.userinfo_url'))) {
return redirect('/error?err=sso_bad_provider_setup');
}

return Settings::get('enableSso')
? Socialite::driver($driver)->redirect()
: redirect('/error?err=sso_disabled');
Expand All @@ -39,6 +46,8 @@ public function callback(Request $request, string $driver)
try {
$socialiteUser = Socialite::driver($driver)->user();
} catch (\Exception $e) {
Log::error($e);

return redirect('/error?err=sso_failed');
}

Expand Down

0 comments on commit d1c2a05

Please sign in to comment.