This article lists the steps to create a Token authentication system for an API.
Install the Security and Maker bundles
composer require symfony/security-bundle
composer require maker --dev
Create a User entity and security configuration
php bin/console make:user
Create an API Token entity
php bin/console make:entity
Class Name: ApiToken
Class properties:
- token (string)
- user (relation ManyToOne with User)
Create migration files and DB tables
php bin/console make:migration
php bin/console doctrine:migrations:migrate
Create the Authenticator class
php bin/console make:auth
Select:
- Empty authenticator
- Class name: ApiTokenAuthenticator