Search by

uxf / security

uxf

Package info

gitlab.com/uxf/security

Issues

pkg:composer/uxf/security

Statistics

Installs: 15 352

Dependents: 1

Suggesters: 0

Stars: 0

3.92.0 2026-11-29 16:21 UTC

This package is auto-updated.

Last update: 2026-11-29 15:56:57 UTC


README

JWT authentication for a Symfony API: password login, refresh tokens, cookie or header transport, role checks on controllers, OpenID Connect login (Google, Apple, …) and an optional OAuth 2.1 authorization server for MCP and other resource servers.

Documentation

Install

$ composer req uxf/security
// config/packages/uxf.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('uxf_security', [
        'user_class' => User::class,                // required
        'base_url' => 'https://uxf.cz',             // required; no trailing slash, it is also the JWT/OAuth issuer
        'public_key' => '%env(AUTH_PUBLIC_KEY)%',   // required
        'private_key' => '%env(AUTH_PRIVATE_KEY)%', // required
        'user_checker' => ActiveUserChecker::class, // required (uxf/cms sets its ActiveUserChecker), see docs/users.md
        // optional
        'access_token_lifetime' => 'P10Y',          // default 1 day
        'refresh_token_lifetime' => 'P20Y',         // default 1 month
        'refresh_token_cookie_path' => '/api/auth', // default null = no refresh token cookie; /api/auth covers refresh and logout
        'cookie_name' => 'Cookie-Name',             // default Authorization - used for header + cookie
        'cookie_secured' => false,                  // default true
        'cookie_http_only' => false,                // default true
        'login_attempt' => [
            'enabled' => true,                      // default true; false = no attempt recorded, no throttling
            'limit' => 5,                           // default 5 failed logins per IP + username ...
            'ip_limit' => 25,                       // default 25 failed logins per IP (0 = off) ...
            'interval' => 900,                      // ... per 900 seconds
            'methods' => [                          // limits of other login methods, see docs/login-attempts.md
                'api' => [],                        // the limit, ip_limit and interval of the password
                'pin' => ['limit' => 0, 'ip_limit' => 0, 'username_limit' => 5],
            ],
        ],
        // OpenID Connect - optional, see docs/oidc.md
        'oidc' => [
            'google' => [
                'client_id' => 'xxx',
            ],
        ],
        // OAuth 2.1 authorization server - optional, see docs/oauth.md
        'oauth' => [
            'enabled' => false,
        ],
        // multi-factor authentication - optional, see docs/mfa.md
        'mfa' => [
            'enabled' => false,
        ],
    ]);
};

All lifetimes are ISO 8601 durations (DateInterval): PT1H, P1D, P30D, …

Values from env

Every option may come from env, with the processor of its type: %env(bool:MFA_REQUIRED)%, %env(int:LOGIN_ATTEMPT_LIMIT)%. Except what the container needs when it is built:

  • user_class and the service IDs user_checker and mfa.totp.encryption.service;
  • login_attempt.enabled, mfa.totp.enabled, mfa.passkey.enabled and mfa.totp.encryption.key_id, the checks of MFA read them;
  • the keys of a map: OIDC providers, login_attempt.methods, mfa.totp.encryption.keys, oauth.clients;
  • a whole list or map from one variable (json:), Symfony refuses it; each item may come from env.

A literal value is checked when the container is built, a value from env when it is used: a second factor without a rate limit fails. bool: reads anything but true, 1, yes and on as false, a typo in MFA_REQUIRED turns the enforcement off. A service reads its env variables when it is built, except the MFA encryption keys: they are read with the first TOTP secret, an environment with MFA off needs none.

Keys

Tokens are signed with RS256. public_key and private_key are the PEM contents (not file paths), usually from env variables:

openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem

Every token carries iss: <base_url> and is rejected when it does not match, so changing base_url or rotating the key pair invalidates every issued access token, including OAuth ones. The public key is published as a JWK set on GET /api/auth/keys (kid is fixed), so another service can verify the tokens without sharing the private key.

Database

The bundle has its own Doctrine entities in the uxf_security schema: RefreshToken, ExternalLogin (OIDC accounts linked to a user), LoginAttempt, used with MFA TOTPCredential and RecoveryCode, and used with OAuth (and MFA) OAuthRefreshToken and OAuthConsumedToken. They reference the user through UserInterface, which the bundle maps to user_class via resolve_target_entities. Generate a migration after installing or upgrading the bundle.