mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-15 09:12:32 -04:00
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: rosslh <ross@rosshill.ca>
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class PasskeyRelyingParty
|
|
{
|
|
/**
|
|
* @return array{id: string, origins: list<string>}|null
|
|
*/
|
|
public static function resolve(Request $request): ?array
|
|
{
|
|
$requestHost = $request->getHost();
|
|
|
|
foreach ([instanceSettings()->fqdn, config('app.url')] as $url) {
|
|
$parts = parse_url((string) $url);
|
|
$host = strtolower($parts['host'] ?? '');
|
|
|
|
if (strtolower($parts['scheme'] ?? '') !== 'https' || $host !== $requestHost) {
|
|
continue;
|
|
}
|
|
if (filter_var(trim($host, '[]'), FILTER_VALIDATE_IP) !== false) {
|
|
continue;
|
|
}
|
|
|
|
$origins = ['https://'.$host.(isset($parts['port']) ? ':'.$parts['port'] : '')];
|
|
|
|
// The fqdn setting stores no port, so a custom port can only come from the request.
|
|
if (! isset($parts['port']) && ! in_array($request->getPort(), [80, 443])) {
|
|
$origins[] = 'https://'.$host.':'.$request->getPort();
|
|
}
|
|
|
|
return ['id' => $host, 'origins' => $origins];
|
|
}
|
|
|
|
if ($requestHost === 'localhost') {
|
|
return ['id' => 'localhost', 'origins' => [$request->getSchemeAndHttpHost()]];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function isAvailable(?Request $request = null): bool
|
|
{
|
|
return (bool) instanceSettings()->is_passkey_enabled
|
|
&& self::resolve($request ?? request()) !== null;
|
|
}
|
|
}
|