Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Webauthn Badge support #693

Open
wants to merge 1 commit into
base: 5.2.x
Choose a base branch
from
Open

Add Webauthn Badge support #693

wants to merge 1 commit into from

Conversation

Spomky
Copy link
Contributor

@Spomky Spomky commented Feb 15, 2025

Target branch: 5.2.x

  • It is a Bug fix
  • It is a New feature
  • Breaks BC
  • Includes Deprecations

Introduce WebauthnBadge, WebauthnPassport, and WebauthnAuthenticator implementations to enable Badge-based authentication.

Example of usage:

<?php

declare(strict_types=1);

namespace App\Security;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Util\TargetPathTrait;
use Webauthn\Bundle\Security\Authentication\WebauthnPassport;
use Webauthn\Bundle\Security\Authentication\WebauthnBadge;
use Webauthn\Bundle\Security\Authentication\WebauthnAuthenticator as BaseWebauthnAuthenticator;

final class WebauthnAuthenticator extends BaseWebauthnAuthenticator
{
    use TargetPathTrait;

    public const string LOGIN_ROUTE = 'app_login';

    public function __construct(
        private readonly UrlGeneratorInterface $urlGenerator,
    ) {
    }

    public function authenticate(Request $request): Passport
    {
        return new WebauthnPassport(
            new WebauthnBadge(
                $request->getHost(),
                $request->request->get('response', '')
            ),
            [
                new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')),
                new RememberMeBadge()
            ]
        );
    }

    protected function getLoginUrl(Request $request): string
    {
        return $this->urlGenerator->generate(self::LOGIN_ROUTE);
    }
}

@Spomky Spomky added the enhancement New feature or request label Feb 15, 2025
@Spomky Spomky self-assigned this Feb 15, 2025
This was linked to issues Feb 15, 2025
@Spomky Spomky added this to the 5.2.0 milestone Feb 15, 2025
@Spomky Spomky changed the title Add Webauthn authentication support Add Webauthn Badge support Feb 15, 2025
Introduces Webauthn-based authentication classes, including `WebauthnAuthenticator`, `WebauthnBadge`, `WebauthnBadgeListener`, and `WebauthnPassport`. These components enable secure, passwordless login using public key credentials, integrating seamlessly into Symfony's security system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant