PHPackages                             gryfoss/single-use-token-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gryfoss/single-use-token-manager

ActiveLibrary

gryfoss/single-use-token-manager
================================

Single-use token management library with multiple cache adapters support

v1.0.0(8mo ago)0137MITPHPPHP ^8.2CI passing

Since Aug 20Pushed 8mo agoCompare

[ Source](https://github.com/GryfOSS/single-use-token-manager)[ Packagist](https://packagist.org/packages/gryfoss/single-use-token-manager)[ RSS](/packages/gryfoss-single-use-token-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

Single Use Token Manager
========================

[](#single-use-token-manager)

[![Tests](https://github.com/GryfOSS/single-use-token-manager/workflows/Tests/badge.svg)](https://github.com/GryfOSS/single-use-token-manager/actions)[![Coverage](https://camo.githubusercontent.com/f236f12a8bcd59be3207979ec4d65f1cbeb83065b7aaa5e0b92a6f6e91bff7a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c6174266c6f676f3d636f6465636f76)](https://github.com/GryfOSS/single-use-token-manager/actions)[![PHP Version](https://camo.githubusercontent.com/df0cb595c63fd33d6fb230cb9e9fe18a23a27a76c211567ed0e68f316435ed29/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e33253230253743253230382e342d3737374242342e7376673f7374796c653d666c6174266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/gryfoss/single-use-token-manager)[![Symfony](https://camo.githubusercontent.com/b120f2953ae1e5f16b89fbe15411cc77d07f5361a3e365c9599f485a7d72f870/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d36253230253743253230372d3030303030302e7376673f7374796c653d666c6174266c6f676f3d73796d666f6e79)](https://symfony.com/)[![PSR-6](https://camo.githubusercontent.com/6db4fce6849d70c79450484dc608a6b0a9d76a4a373e9e0a2d9d2156d623c247/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d362d6f72616e67652e7376673f7374796c653d666c6174)](https://www.php-fig.org/psr/psr-6/)[![Docker](https://camo.githubusercontent.com/9b1aaabbc58e643571627bba3101cc7163007f0097d3ea16c5683d68261183c0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f636b65722d737570706f727465642d3234393645442e7376673f7374796c653d666c6174266c6f676f3d646f636b6572266c6f676f436f6c6f723d7768697465)](docker-compose.yml)

[![License: MIT](https://camo.githubusercontent.com/e1ebf561b8f09f4b1bc1a606c77956f8c6c206c904664d03c69b830845055ffb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c6174)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/50c507cbd226208db0a45488031800349a2b28ee95d74b42f78e6395f3be73ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e7376673f7374796c653d666c6174266c6f676f3d7061636b6167697374)](https://packagist.org/packages/gryfoss/single-use-token-manager)[![Total Downloads](https://camo.githubusercontent.com/4b0c1266108a19ed2baf055d3ad0c5dbc65bb342753b0943d7c7bf3d3b87c5d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e7376673f7374796c653d666c6174266c6f676f3d7061636b6167697374)](https://packagist.org/packages/gryfoss/single-use-token-manager)

A comprehensive single-use token management library using Symfony Cache with support for multiple cache adapters.

Features
--------

[](#features)

- **Token Creation &amp; Consumption**: Create unique single-use tokens with optional TTL and consume them
- **Multiple Cache Adapters**: Support for ArrayAdapter, Redis with tags, and Redis without tags
- **Tag-Aware Clearing**: Efficient token clearing with tag-aware adapters
- **Full Test Coverage**: 100% unit test coverage with comprehensive functional tests
- **Validation &amp; Serialization**: Built-in validation and JSON serialization support
- **Docker Integration**: Easy testing with Docker-based Redis instances
- **Comprehensive Documentation**: Extensive PHPDoc documentation for all classes and methods
- **Type Safety**: Full type declarations and strict typing throughout the codebase

Installation
------------

[](#installation)

```
composer require gryfoss/single-use-token-manager
```

Quality &amp; Compatibility
---------------------------

[](#quality--compatibility)

- **🧪 Tests**: Automated testing with GitHub Actions across multiple PHP versions
- **📊 Coverage**: 100% code coverage maintained with comprehensive unit and functional tests
- **🐘 PHP Support**: Compatible with PHP 8.2, 8.3, and 8.4
- **🎼 Symfony Integration**: Built on Symfony 6 &amp; 7 components (Cache, Validator, Serializer, UID)
- **📋 PSR Compliance**: Implements PSR-6 (Caching Interface) standards
- **🐳 Docker Support**: Complete Docker Compose setup for testing environments
- **📦 Stable Release**: Available on Packagist with semantic versioning
- **📥 Community Adoption**: Tracked downloads and usage statistics
- **📄 MIT License**: Free and open source with permissive licensing

Quality &amp; Compatibility
---------------------------

[](#quality--compatibility-1)

- **🧪 Tests**: Automated testing with GitHub Actions across multiple PHP versions
- **📊 Coverage**: 100% code coverage maintained with comprehensive unit and functional tests
- **🐘 PHP Support**: Compatible with PHP 8.2, 8.3, and 8.4
- **🎼 Symfony Integration**: Built on Symfony 6 &amp; 7 components (Cache, Validator, Serializer, UID)
- **� PSR Compliance**: Implements PSR-6 (Caching Interface) standards
- **�📦 Stable Release**: Available on Packagist with semantic versioning
- **📥 Community Adoption**: Tracked downloads and usage statistics
- **📄 MIT License**: Free and open source with permissive licensing

Requirements
------------

[](#requirements)

- PHP 8.2 or higher (tested on PHP 8.2, 8.3, and 8.4)
- Redis extension (for Redis-based tests)
- Docker and Docker Compose (for functional tests)

API Documentation
-----------------

[](#api-documentation)

All classes and methods include comprehensive PHPDoc documentation with:

- Detailed descriptions of functionality
- Parameter and return type documentation
- Usage examples and best practices
- Exception handling information
- Implementation notes for different cache adapters

### Core Classes

[](#core-classes)

- **`TokenServiceInterface`**: Defines the contract for token management services
- **`TokenService`**: Main implementation with cache adapter support
- **`TokenInterface`**: Contract for token objects
- **`Token`**: Immutable token implementation with UUID v6 identifiers
- **`TokenIdentifier`**: DTO for token identification with validation

Testing
-------

[](#testing)

[![Tests](https://github.com/GryfOSS/single-use-token-manager/workflows/Tests/badge.svg)](https://github.com/GryfOSS/single-use-token-manager/actions) [![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](https://github.com/GryfOSS/single-use-token-manager/actions)

This project includes comprehensive testing with three different cache adapter scenarios:

### Matrix Testing

[](#matrix-testing)

The GitHub Actions workflow tests the library against multiple PHP versions:

- **PHP 8.2**: Minimum supported version
- **PHP 8.3**: LTS version with coverage reporting
- **PHP 8.4**: Latest stable version

### Test Coverage

[](#test-coverage)

Each PHP version runs:

- ✅ **Unit Tests**: Complete test suite with 32 tests and 75 assertions
- ✅ **Functional Tests**: All three cache adapter scenarios
- ✅ **Coverage Verification**: 100% code coverage (validated on PHP 8.3)

### Cache Adapter Testing

[](#cache-adapter-testing)

### 1. ArrayAdapter (Offline Storage)

[](#1-arrayadapter-offline-storage)

- In-memory storage, no persistence
- Ideal for development and unit testing
- No external dependencies

### 2. Redis with Tags (Online Storage + Tag Support)

[](#2-redis-with-tags-online-storage--tag-support)

- Persistent Redis storage with tag support
- Efficient token clearing using cache tags
- Requires Redis server

### 3. Redis without Tags (Online Storage, No Tag Support)

[](#3-redis-without-tags-online-storage-no-tag-support)

- Persistent Redis storage without tag support
- Full cache clearing for token management
- Requires Redis server

### GitHub Actions CI/CD

[](#github-actions-cicd)

The project includes automated testing via GitHub Actions that verifies:

✅ **Unit Tests**: All 32 unit tests pass ✅ **100% Code Coverage**: Automatically verified (build fails if not 100%) ✅ **Functional Tests**: All cache adapters tested (ArrayAdapter, Redis+Tags, Redis-NoTags)

**Workflows:**

- `.github/workflows/ci.yml` - Main CI pipeline (focuses on the 3 core requirements)
- `.github/workflows/test.yml` - Comprehensive testing with matrix
- `.github/workflows/simple-test.yml` - Detailed multi-job pipeline

### Local Coverage Verification

[](#local-coverage-verification)

```
# Verify 100% coverage locally (same check as GitHub Actions)
./verify-coverage.sh
```

### Manual Testing

[](#manual-testing)

```
# Start Docker services
./test-runner.sh start

# Run specific test suites
./test-runner.sh test array           # ArrayAdapter tests
./test-runner.sh test redis_tags      # Redis with tags tests
./test-runner.sh test redis_no_tags   # Redis without tags tests
./test-runner.sh test all             # All functional tests

# Run unit tests
./test-runner.sh unit

# Run everything
./test-runner.sh full

# Clean up
./test-runner.sh clean
```

### Composer Scripts

[](#composer-scripts)

```
composer test:unit                    # Run unit tests with coverage
composer test:functional-array        # Run ArrayAdapter tests
composer test:functional-redis-tags   # Run Redis with tags tests
composer test:functional-redis-no-tags # Run Redis without tags tests
composer test:functional             # Run all functional tests
composer test:full                   # Run all tests
composer docker:start               # Start Docker services
composer docker:stop                # Stop Docker services
composer docker:clean               # Clean up Docker
```

Architecture
------------

[](#architecture)

### Core Classes

[](#core-classes-1)

- **TokenService**: Main service implementing TokenServiceInterface
- **Token**: Token entity with UUID, type, payload, and TTL
- **TokenIdentifier**: DTO for token validation and serialization
- **TokenInterface**: Contract for token objects

### Cache Strategy

[](#cache-strategy)

The service automatically detects cache adapter capabilities:

- **Tag-Aware Adapters**: Use cache tags for efficient selective clearing
- **Non-Tag-Aware Adapters**: Use full cache pool clearing
- **ArrayAdapter**: In-memory storage for development/testing

### Validation &amp; Serialization

[](#validation--serialization)

- **Symfony Validator**: Attribute-based validation (NotBlank, NotNull, Type)
- **Symfony Serializer**: JSON serialization with SerializedName attributes
- **OpenAPI Integration**: API documentation attributes

Usage
-----

[](#usage)

```
use GryfOSS\SingleUseTokenManager\TokenService;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

// Create service with ArrayAdapter
$cache = new ArrayAdapter();
$tokenService = new TokenService($cache);

// Create a token
$token = $tokenService->createToken('user_session', ['user_id' => 123], 3600);

// Consume the token
$consumedToken = $tokenService->consumeToken($token->getUid());

// Clear all tokens
$tokenService->clearAllTokens();
```

### Advanced Usage

[](#advanced-usage)

```
use GryfOSS\SingleUseTokenManager\TokenService;
use GryfOSS\SingleUseTokenManager\TokenIdentifier;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Validator\Validation;

// Redis with tag support
$redis = new \Redis();
$redis->connect('localhost', 6379);
$cache = new RedisTagAwareAdapter($redis);
$tokenService = new TokenService($cache);

// Create multiple tokens
$loginToken = $tokenService->createToken('login', ['user_id' => 123], 3600);
$resetToken = $tokenService->createToken('reset', 'password-data', 1800);

// Validate token identifier
$tokenIdentifier = new TokenIdentifier();
$tokenIdentifier->token = $loginToken->getUid();

$validator = Validation::createValidatorBuilder()
    ->enableAttributeMapping()
    ->getValidator();

$violations = $validator->validate($tokenIdentifier);
if (count($violations) === 0) {
    echo "Token is valid!";
}

// Clear all tokens efficiently (uses tags)
$tokenService->clearAllTokens();
```

Test Coverage
-------------

[](#test-coverage-1)

- **Unit Tests**: 32 tests, 75 assertions, 100% code coverage
- **Functional Tests**: Multiple scenarios across 3 cache adapters
- **Integration Tests**: Docker-based Redis testing
- **Validation Tests**: Comprehensive constraint testing

Development
-----------

[](#development)

### Docker Services

[](#docker-services)

The project includes Docker Compose configuration for:

- **redis**: Redis instance on port 6379 (with tag support)
- **redis-no-tags**: Redis instance on port 6380 (without tag support)

### Test Structure

[](#test-structure)

```
tests/
├── Behat/
│   ├── ArrayAdapterTokenServiceContext.php
│   ├── RedisTagsTokenServiceContext.php
│   ├── RedisNoTagsTokenServiceContext.php
│   ├── TokenContext.php
│   └── TokenServiceContext.php (legacy)
├── TokenServiceTest.php
├── TokenTest.php
└── TokenIdentifierTest.php

features/
├── token.feature
├── tokenService.feature (legacy)
├── tokenService-array.feature
├── tokenService-redis-tags.feature
└── tokenService-redis-no-tags.feature

```

Badge Reference
---------------

[](#badge-reference)

BadgeDescriptionPurpose[![Tests](https://github.com/GryfOSS/single-use-token-manager/workflows/Tests/badge.svg)](https://github.com/GryfOSS/single-use-token-manager/workflows/Tests/badge.svg)CI/CD Pipeline StatusShows if all tests pass across PHP 8.2, 8.3, 8.4[![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)Code CoverageIndicates 100% test coverage maintained[![PHP](https://camo.githubusercontent.com/c2e1cc90c67c4c950133255a3bf1f7b083bd56cb2eb5418d2197225373153722/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e33253230253743253230382e342d3737374242342e737667)](https://camo.githubusercontent.com/c2e1cc90c67c4c950133255a3bf1f7b083bd56cb2eb5418d2197225373153722/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e33253230253743253230382e342d3737374242342e737667)PHP Version SupportSupported PHP versions for compatibility[![Symfony](https://camo.githubusercontent.com/bb5e0c8bc8d690a41f81ad07c31ba797aff347083039246519af600665e0b3d4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d36253230253743253230372d3030303030302e737667)](https://camo.githubusercontent.com/bb5e0c8bc8d690a41f81ad07c31ba797aff347083039246519af600665e0b3d4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d36253230253743253230372d3030303030302e737667)Framework IntegrationBuilt with Symfony components[![PSR-6](https://camo.githubusercontent.com/5b75bb08e32fd82eb79eff7a77210d6f119f227bf2f88e83ca44e6069e59a078/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d362d6f72616e67652e737667)](https://camo.githubusercontent.com/5b75bb08e32fd82eb79eff7a77210d6f119f227bf2f88e83ca44e6069e59a078/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d362d6f72616e67652e737667)Standards ComplianceImplements PSR-6 Caching Interface[![Docker](https://camo.githubusercontent.com/1c3ab1f831d28dca3816d3df0b0fbf145467c0a790db2ef28d2494657efd8de3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f636b65722d737570706f727465642d3234393645442e737667)](https://camo.githubusercontent.com/1c3ab1f831d28dca3816d3df0b0fbf145467c0a790db2ef28d2494657efd8de3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f636b65722d737570706f727465642d3234393645442e737667)Container SupportDocker Compose for testing environments[![License](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)License TypeMIT License for open source usage[![Version](https://camo.githubusercontent.com/3785ceef5ed6c6421cf2fa9126018d2215ac61abf9d16dbd2f05e4d1e2c77d61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e737667)](https://camo.githubusercontent.com/3785ceef5ed6c6421cf2fa9126018d2215ac61abf9d16dbd2f05e4d1e2c77d61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e737667)Latest ReleaseCurrent stable version on Packagist[![Downloads](https://camo.githubusercontent.com/982a4d3320f80c3f32c41bbb9eb11f616392f4a7a3b6f4d5d1ed84160c739a04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e737667)](https://camo.githubusercontent.com/982a4d3320f80c3f32c41bbb9eb11f616392f4a7a3b6f4d5d1ed84160c739a04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677279666f73732f73696e676c652d7573652d746f6b656e2d6d616e616765722e737667)Community UsageTotal package downloadsLicense
-------

[](#license)

MIT License

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance62

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

262d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b76a5fac115d24d698d09cc939a6922bf309732ae61d0f2f215ae9e7397658ea?d=identicon)[ideaconnect](/maintainers/ideaconnect)

---

Top Contributors

[![drabarek](https://avatars.githubusercontent.com/u/7080725?v=4)](https://github.com/drabarek "drabarek (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/gryfoss-single-use-token-manager/health.svg)

```
[![Health](https://phpackages.com/badges/gryfoss-single-use-token-manager/health.svg)](https://phpackages.com/packages/gryfoss-single-use-token-manager)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M234](/packages/api-platform-core)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M308](/packages/easycorp-easyadmin-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M385](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
