Download the PHP package ecourty/token-bundle without Composer

On this page you can find all versions of the php package ecourty/token-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package token-bundle

Token Bundle

CI

A Symfony bundle for managing secure, typed, and revocable tokens attached to any entity — for password resets, email verification, share links, and more.

Table of Contents


Requirements


Installation

Register the bundle in config/bundles.php (if not using Symfony Flex):

Create the tokens table with a Doctrine migration:

The bundle automatically registers its Doctrine entity mapping — no manual configuration required.


Core Features


Configuration

Option Type Default Description
token_length int 64 Length of the generated token string (min: 16)

Usage

Making an Entity a Token Subject

Any Doctrine entity can become a token subject by implementing TokenSubjectInterface:

Creating a Token

Inject TokenManager and call create():

With payload and max-uses:

Retrieving a Token

Use get() to look up a token by its string value and validate it without consuming it. This is useful to check if a token is valid before showing a form or performing an action:

get() throws the same exceptions as consume() if the token is invalid.

Consuming a Token

consume() accepts either a token string (with its type) or a Token entity directly:

Both paths validate the token before consuming it and throw the same exceptions:

Tip: All token exceptions extend AbstractTokenException (a RuntimeException), so you can catch them all at once if needed.

Revoking Tokens

Finding a Valid Token

Returns the first valid (not expired, not consumed, not revoked, not at max uses) token for the given subject and type:

Resolving the Subject Entity

After consuming or finding a token, retrieve the original subject entity directly:

Protecting Controller Routes

Use the #[RequiresToken] attribute to protect a controller action with a token check. The listener validates the token before the controller executes:

By default, the token is read from the X-Token HTTP header via the built-in HeaderTokenResolver.

The attribute accepts two parameters:

Parameter Type Default Description
type string (required) Token type to validate against
resolver class-string HeaderTokenResolver::class FQCN of a TokenResolverInterface to use

Built-in resolvers:

Resolver Reads from
HeaderTokenResolver X-Token HTTP header (default)
QueryStringTokenResolver ?token= query string parameter

Custom resolver:

Implement TokenResolverInterface to extract the token from anywhere in the request (cookies, custom headers, etc.):

Resolver classes are automatically tagged and discovered when they implement TokenResolverInterface.

Handling access denied:

When a token is missing, invalid, expired, or revoked, a TokenAccessDeniedException is thrown. You can handle it globally by listening to the TokenAccessDeniedEvent:

The event provides $event->request, $event->exception (the underlying token exception), and $event->tokenType. Setting a response on the event prevents the exception from propagating.


Events

The bundle dispatches Symfony events on token lifecycle actions:

Event Dispatched when Extra properties
TokenCreatedEvent After a token is created & persisted $createdAt
TokenConsumedEvent After a token is successfully consumed $consumedAt
TokenRevokedEvent After a single token is revoked via revoke() $revokedAt
TokenAccessDeniedEvent When a #[RequiresToken] check fails (dispatched from the exception listener) $request, $exception, $tokenType

Note: revokeAll() performs a bulk SQL UPDATE for performance and does not dispatch individual TokenRevokedEvent per token.

All events carry the Token entity via $event->token.

Example listener:


Exceptions

All exceptions extend AbstractTokenException (RuntimeException):

Exception Thrown when
TokenNotFoundException Token string not found or type mismatch
TokenExpiredException Token has expired
TokenRevokedException Token was revoked
TokenAlreadyConsumedException Single-use token already consumed
TokenMaxUsesReachedException Token has reached its maximum number of uses
TokenAccessDeniedException Token check failed on a #[RequiresToken] route

Console Command


Development


License

This bundle is released under the MIT License.


All versions of token-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
doctrine/doctrine-bundle Version ^2.0|^3.0
doctrine/orm Version ^3.0
symfony/config Version ^7.0|^8.0
symfony/console Version ^7.0|^8.0
symfony/dependency-injection Version ^7.0|^8.0
symfony/event-dispatcher Version ^7.0|^8.0
symfony/http-foundation Version ^7.0|^8.0
symfony/http-kernel Version ^7.0|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ecourty/token-bundle contains the following files

Loading the files please wait ...