letdoittoday/rabbitmq-access-token-bundle
A PHP bundle for RabbitMQ access token authentication, offering OAuth 2.0-style token handling so services can authenticate against RabbitMQ without static credentials. A small, low-profile package for projects already in the letdoittoday ecosystem.
The first thing to internalize: this is a Symfony bundle, not a Laravel package. There is no extra.laravel.providers auto-discovery, no php artisan vendor:publish, no facade, and no config file published into config/. Composer will install it, but Laravel will not wire it up for you. Read composer.json first and confirm its symfony/* and php constraints actually overlap with your runtime — a 2020-era bundle was almost certainly built against Symfony 4.4/5.0 and PHP 7.2–7.4.
Before touching code, confirm the broker side, because this is where most of the value (and most of the failure) lives:
rabbitmq_auth_backend_oauth2 (or equivalent) enabled and configured with a signing key and resource-server settings. A stock RabbitMQ will reject the token.A minimal first use case is the smallest possible: obtain a token from the token provider, then establish a single php-amqplib connection using that token as the password (RabbitMQ OAuth2 carries the bearer token in the password field; the username is effectively ignored). Publish one message and confirm it lands in the queue. If that works, the rest of the work is lifecycle management.
Where to look first in the repo: the token provider service class and its constructor signature. That is the only piece with real logic; everything else is Symfony container plumbing you will not use.
There are three realistic integration shapes, from lowest to highest effort.
Pattern A — Use the token provider as a plain object. Instantiate the provider manually in a small Laravel service, feed it the endpoint/client credentials from config/services.php, and expose a token(): string method. This skips the bundle's container wiring entirely and avoids dragging Symfony's DI into your app. Wrap it behind your own interface (e.g. App\Contracts\RabbitTokenProvider) so tests and future swaps do not touch vendor code.
Pattern B — Bridge into the Laravel AMQP queue driver. The common Laravel AMQP queue driver is vladimir-yuldashev/laravel-queue-rabbitmq. It builds a php-amqplib connection from config/queue.php. Since the token changes over time, do not bake it into config at boot; instead register a container singleton that returns the current cached token, and override the connection factory (or decorate the connector) so it reads the password from that singleton at connect time. Cache the token in Laravel's cache/Cache::remember keyed off its exp claim with a safety margin, so multiple worker processes do not hammer the IdP.
Pattern C — Refresh-on-schedule. For long-running queue workers, the connection outlives the token. Two approaches work: (i) short-lived connections — reconnect per batch and re-read the token; or (ii) listen on JobProcessing/JobProcessed and compare the token's expiry against a skew window, forcing a reconnect when close. Never hold a token in memory indefinitely; the broker will validate it per-command and reject expired ones mid-stream.
For publish-only paths, Pattern A + a Cache::remember-backed token is usually enough. For consumers, plan for reconnect logic up front — an AMQPConnectionException mid-consume with an expired token is the failure mode you will hit in production.
Configure via env: token endpoint URL, client id, client secret, scope, and a refresh skew (e.g. 60–120 seconds). Keep all of it in config/services.php under a dedicated key, not scattered through the bundle's assumptions.
ContainerBuilder, not Laravel's container. Budget for manual wiring or extraction.. and -/_; php-amqplib treats the password opaquely, but do not URL-encode or truncate it. Do not log it — add a redaction in your AMQP connector logs.Http::fake() or a PSR-18 mock), freeze time to exercise the refresh window, and assert reconnect happens exactly once when a token is near expiry.RabbitTokenProvider interface; keep the vendor class behind an adapter so a future Laravel-native implementation (e.g. Cache + Http) is a one-file swap and not a rewrite.How can I help you explore Laravel packages today?