mirror of
https://github.com/koel/koel
synced 2024-12-22 10:33:16 +00:00
38 lines
908 B
PHP
38 lines
908 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Services;
|
||
|
|
||
|
use App\Models\User;
|
||
|
use App\Values\SSOUser;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Support\Facades\Log;
|
||
|
use Symfony\Component\HttpFoundation\IpUtils;
|
||
|
use Throwable;
|
||
|
|
||
|
class ProxyAuthService
|
||
|
{
|
||
|
public function __construct(private UserService $userService)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public function tryGetProxyAuthenticatedUserFromRequest(Request $request): ?User
|
||
|
{
|
||
|
if (!self::validateProxyIp($request)) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
return $this->userService->createOrUpdateUserFromSSO(SSOUser::fromProxyAuthRequest($request));
|
||
|
} catch (Throwable $e) {
|
||
|
Log::error($e->getMessage(), ['exception' => $e]);
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private static function validateProxyIp(Request $request): bool
|
||
|
{
|
||
|
return IpUtils::checkIp($request->ip(), config('koel.proxy_auth.allow_list'));
|
||
|
}
|
||
|
}
|