Files
coolify/app/Support/PasskeyRelyingParty.php
T
Aditya Tripathi 7bed78c81e feat(auth): add passkey sign-in
Enable Fortify passkeys (laravel/passkeys) with the @laravel/passkeys
client. Users can sign in with a passkey, confirm sensitive actions with
one, and add, rename, and delete passkeys on the Profile page.

- Resolve the relying party for each request from the instance URL, then
  APP_URL, then localhost. Passkey routes return 404 on other hosts.
- Add the is_passkey_enabled instance setting (Settings > Advanced).
- Use a hex user handle (laravel/passkeys-server#41).
- Rate limit the passkey routes by client IP.
- Record audit events for registered, verified, and deleted passkeys.
2026-10-13 04:01:40 +00:00

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;
}
}