zen0x7/tokenizer

PHP SDK for Service Framework authentication and token generation.

Maintainers

Package info

github.com/Zen0x7/Tokenizer

pkg:composer/zen0x7/tokenizer

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-04-27 18:23 UTC

This package is auto-updated.

Last update: 2026-04-27 18:48:18 UTC


README

A high-performance PHP SDK for generating authenticated and encrypted JSON Web Tokens (JWT) for the Service Framework cluster.

Features

  • JWE/JWS Support: Fully compatible with the C++ implementation (AES-256-GCM + HMAC-SHA256).
  • Fluent Builder: Easy token construction with a human-readable interface.
  • Grants & Wildcards: Full support for resource-based grants (channels:*, cache:user.*, system:admin).
  • Laravel Ready: Easily integrable into any PHP 8.1+ project or framework.

Installation

Install via Composer:

composer require zen0x7/tokenizer

Usage

Generating a Token

use Zen0x7\Tokenizer\TokenBuilder;

$builder = TokenBuilder::create()
    ->withSubject('user_123')
    ->withDuration(3600) // 1 hour
    ->withSystemPermissions(['admin', 'broadcast'])
    ->withChannelPermissions('chat.general', ['read', 'write'])
    ->withChannelPermissions('private.*', ['read'])
    ->withCachePermissions('user:profile:*', ['read', 'write', 'delete'])
    ->withClaim('custom_field', 'custom_value');

$token = $builder->build(
    signatureKey: 'base64:your_signature_key_here',
    encryptionKey: 'base64:your_encryption_key_here'
);

echo "Authorization: Bearer " . $token;

Key Formats

The SDK supports both raw binary keys and base64-encoded keys (prefixed with base64:).

// Example with base64 keys
$signatureKey = 'base64:c2VjcmV0X3NpZ25hdHVyZV9rZXlfZm9yX2V4YW1wbGVfdXNhZ2U=';
$encryptionKey = 'base64:YWVzXzI1Nl9nY21fZXhhbXBsZV9rZXlfMzJfYnl0ZXM=';

Security

This SDK implements:

  1. JWS (JSON Web Signature): HMAC-SHA256 protecting the entire token.
  2. JWE (JSON Web Encryption): AES-256-GCM encrypting the payload.
  3. Base64Url: Standard URL-safe encoding for JWT parts.

License

MIT