ecphp/eu-login-api-authentication-bundle
This package, EU Login API Authentication Bundle, integrates with the EU Login API to authenticate users via European Union identity providers (e.g., eIDAS). To get started:
Installation:
composer require ecphp/eu-login-api-authentication-bundle
Ensure your project meets the updated requirements:
1.0.6).symfony/http-foundation) or wrap the bundle in a Laravel-specific adapter.Configuration: Publish the bundle’s config:
php artisan vendor:publish --provider="ECPHP\EuLoginApiAuthenticationBundle\EuLoginApiAuthenticationBundle"
Update .env with your EU Login API credentials (e.g., EU_LOGIN_CLIENT_ID, EU_LOGIN_SECRET).
First Use Case:
Add the authentication route to your routes/web.php or routes/api.php:
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class EuLoginController extends AbstractController
{
#[Route('/login/eu', name: 'eu_login')]
public function redirectToEuLogin(): Response
{
return $this->redirect($this->get('eu_login.api_authenticator')->getLoginUrl());
}
}
Test the flow by visiting /login/eu and verifying the redirect to the EU Login provider.
Authentication Flow:
EuLoginApiAuthenticator service to generate login URLs and handle callbacks:
$loginUrl = $this->get('eu_login.api_authenticator')->getLoginUrl(['redirect_uri' => route('eu_login.callback')]);
#[Route('/login/eu/callback', name: 'eu_login.callback')]
public function handleEuLoginCallback(Request $request)
{
$user = $this->get('eu_login.api_authenticator')->authenticate($request);
// Store user data (e.g., in session or database).
return $this->redirectToRoute('home');
}
User Data Handling:
$userInfo = $this->get('eu_login.api_authenticator')->getUserInfo($user);
// Example: $userInfo['given_name'], $userInfo['email']
Session Integration:
$this->get('security.token_storage')->setToken(
new UsernamePasswordToken($request->getSession(), $user->getEmail(), $user->getRoles())
);
Laravel-Specific:
namespace App\Services;
use Illuminate\Support\Facades\Facade;
class EuLoginService extends Facade
{
protected static function getFacadeAccessor() { return 'eu_login.api_authenticator'; }
}
Auth facade to handle user sessions:
Auth::loginUsingId($user->getId());
Custom Providers:
EuLoginApiAuthenticator to support additional EU member state providers or custom scopes:
class CustomEuLoginAuthenticator extends EuLoginApiAuthenticator
{
protected function getProviderConfig(): array
{
return array_merge(parent::getProviderConfig(), [
'scopes' => ['openid', 'profile', 'email', 'custom_scope'],
]);
}
}
config/services.php:
'eu_login.api_authenticator' => App\Services\CustomEuLoginAuthenticator::class,
Testing:
1.0.6) to mock the EU Login API:
$this->get('eu_login.api_authenticator')->shouldReceive('fetchUserInfo')
->once()
->andReturn(['given_name' => 'Test', 'email' => 'test@example.com']);
1.0.6Symfony 7 Compatibility:
1.0.5 or upgrade Symfony first.composer.json to require ^7.0 for Symfony bundles and run:
composer update symfony/* --with-all-dependencies
PHP Version:
php -v # Should show 8.1.x or 8.2.x
Deprecations:
refactor: fix deprecation commit (cc4ebf7) and its revert (a02cf42) suggest internal API changes. Avoid relying on undocumented methods in the bundle’s core classes.Callback Errors:
/login/eu/callback route fails, verify:
state parameter matches the session (enable EU_LOGIN_DEBUG=true in .env to log states).redirect_uri in the initial request matches the callback URL exactly (including http vs. https).User Info Missing:
profile, email). Add these to your provider config:
# config/packages/eu_login_api_authentication.yaml
eu_login_api_authentication:
scopes: ['openid', 'profile', 'email']
Static Analysis Warnings:
psalm fixes in 1.0.6 may reveal type-related issues. Run:
vendor/bin/psalm --init
vendor/bin/psalm
psalm.xml if needed.Custom User Entity:
EuLoginUserProvider:
class CustomUserProvider extends EuLoginUserProvider
{
public function loadUserByToken(string $token): UserInterface
{
$userData = parent::loadUserByToken($token);
return new App\Entity\User([
'name' => $userData['given_name'],
'email' => $userData['email'],
// Add custom fields.
]);
}
}
config/packages/security.yaml:
providers:
eu_login:
id: App\Security\CustomUserProvider
API Rate Limiting:
$client = new Client([
'middleware' => [
new RetryMiddleware([
'max_retries' => 3,
'delay' => 100,
]),
],
]);
Logging:
.env:
EU_LOGIN_DEBUG=true
EU_LOGIN_LOG_LEVEL=debug
var/log/dev.log (Symfony) or Laravel’s storage/logs.CI/CD Updates:
scrutinizer in favor of readthedocs.yml. Update your CI config to avoid failures:
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: php vendor/bin/phpunit
How can I help you explore Laravel packages today?