login512 / login512-symfony-bundle
Symfony bundle for Login512 (face login + passkeys): security authenticator, nonce endpoint and API client
Package info
github.com/login512/login512-symfony-bundle
Type:symfony-bundle
pkg:composer/login512/login512-symfony-bundle
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
- symfony/framework-bundle: ^6.4|^7.0
- symfony/security-bundle: ^6.4|^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Symfony bundle for Login512 (face login + passkeys, ML-DSA-65 signed tokens): a security authenticator that turns
a Login512 token into a Symfony session, a nonce endpoint (login CSRF protection) and an autowirable API client.
Symfony 6.4 or 7.x, PHP 8.1+, ext-curl. Tested inside a real Symfony 7.4 app (tools/audit/symfony_docker/).
Installation
composer require login512/login512-symfony-bundle
Without Packagist (ZIP)
mkdir -p packages/login512-symfony-bundle
curl -sO https://login512.com/packages/symfony.zip
unzip symfony.zip -d packages/login512-symfony-bundle
composer config repositories.login512 path packages/login512-symfony-bundle
composer require 'login512/login512-symfony-bundle:*'
Symfony Flex adds Login512\SymfonyBundle\Login512SymfonyBundle to config/bundles.php (add it by hand without Flex).
The core PHP SDK is bundled in core/Login512.php (class \Login512\Login512); no other package is needed.
.env.local
LOGIN512_SECRET_KEY=l512_sk_live_your_secret LOGIN512_PUBLISHABLE_KEY=l512_pk_live_your_key
config/routes/login512.yaml
login512: resource: '@Login512SymfonyBundle/config/routes.php' # GET /login512/nonce, POST /login512/verify
config/packages/security.yaml
security: providers: login512: id: Login512\SymfonyBundle\Security\Login512UserProvider firewalls: main: lazy: true provider: login512 custom_authenticators: - Login512\SymfonyBundle\Security\Login512Authenticator access_control: - { path: ^/account, roles: ROLE_USER }
Login page
<div id="login512"></div> <script src="https://login512.com/sdk/login512-sdk.js"></script> <script> (async () => { const cfg = await (await fetch('/login512/nonce', { credentials: 'same-origin' })).json(); Login512.init({ publishableKey: cfg.publishableKey, endpoint: cfg.endpoint }).mountButton('#login512', { nonce: cfg.nonce, onSuccess: async (token) => { const r = await fetch(cfg.verifyUrl, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }), }); const res = await r.json(); // 200 {ok: true, user, redirect} | 401 {ok: false, error: "CODE"} if (res.ok) location.href = res.redirect; }, }); })(); </script>
POST /login512/verify logs the user in only when the token is valid, was not used before, does not require a
step-up and carries the nonce stored in this browser's session. Errors: NONCE_REQUIRED, NONCE_MISMATCH,
TOKEN_ALREADY_USED, TOKEN_BAD_SIGNATURE, STEP_UP_REQUIRED, ... (401), ORIGIN_NOT_ALLOWED (403),
JSON_BODY_REQUIRED (415).
Who is logged in
By default the user is a Login512\SymfonyBundle\Security\Login512User: identifier = claims.sub (the
external_user_id you chose at enrollment), role ROLE_USER, getClaims(). It is not looked up in your own user
provider, so a Login512 subject called admin is not your admin.
To log people in as your own user class, implement the mapper and name it in the config:
// src/Security/Login512UserMapper.php final class Login512UserMapper implements \Login512\SymfonyBundle\Security\Login512UserMapperInterface { public function __construct(private UserRepository $users) {} public function mapUser(array $claims): UserInterface { // a column only this integration writes; never match on username or email return $this->users->findOneBy(['login512Sub' => $claims['sub']]) ?? throw new UserNotFoundException(); } }
# config/packages/login512.yaml login512: user_mapper: App\Security\Login512UserMapper
and use your normal entity provider for the firewall instead of Login512UserProvider.
Verify a token yourself
use Login512\SymfonyBundle\Login512Client; #[Route('/api/verify-token', methods: ['POST'])] public function verify(Request $request, Login512Client $login512): JsonResponse { $res = $login512->verifyToken((string) $request->toArray()['token']); // optional 2nd argument: expected nonce // session_allowed, not valid: a valid token can still require a step-up. Tokens are single-use. if (empty($res['session_allowed'])) { return new JsonResponse(['error' => $res['error'] ?? 'STEP_UP_REQUIRED'], 401); } return new JsonResponse(['sub' => $res['claims']['sub']]); }
Options (config/packages/login512.yaml, all optional)
| key | default |
|---|---|
secret_key |
%env(LOGIN512_SECRET_KEY)% |
publishable_key |
%env(default::LOGIN512_PUBLISHABLE_KEY)% |
endpoint |
https://api.login512.com |
check_path |
/login512/verify |
require_nonce |
true |
default_target_path |
/ |
user_mapper |
none |
Changes
- 2.1.1: first installable version. 2.1.0 was never published as an archive and its authenticator verified every
Authorization: Bearerheader, ignored step-up and the nonce, logged a token without a subject in as "anonymous" and loaded the user from the app's own provider by name (subjectadmin= your admin).