Download the PHP package mrsuner/laravel-api-keys without Composer

On this page you can find all versions of the php package mrsuner/laravel-api-keys. 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 laravel-api-keys

Laravel API Keys

Developer API key management for Laravel — prefix-routed keys (sk_live_…), rotation with an overlap window, per-key rate limits, abilities, and async usage tracking.

Tests Latest Version on Packagist

It layers over Laravel Sanctum rather than replacing it: a resolved key authenticates the request through the existing auth:sanctum stack, so every route, policy, and response envelope keeps working unchanged. The package runs standalone in any Laravel 12/13 app and auto-wires into mrsuner/laravel-api-boilerplate when present (its audit_log() helper, InternalIpWhitelist, and EnsureAdminAccess middleware are detected at runtime; none are required).

Why not just Sanctum tokens?

Concern Sanctum token Developer API key
Format Opaque hash, no prefix sk_live_XXXX prefix-routed
Rate limit Global throttle only Configurable per key
Rotation Delete + recreate Rotate with overlap window
Usage tracking last_used_at only IP + endpoint + request count
Admin visibility Token list by user Revoke + per-key usage stats

Requirements

Development

The committed lock file targets PHP 8.3 and Laravel 13. Run composer install and composer test for that baseline. CI separately resolves dependencies for each supported Laravel/PHP combination, including Laravel 12 on PHP 8.2.

Installation

The service provider is auto-discovered. It also registers the api.key and api.ability middleware aliases, so you do not need to edit bootstrap/app.php.

Key format

Only a SHA-256 hash of the token segment is stored (key_hash), and authentication also requires the raw key's environment segment to match the stored environment. The plaintext key is returned exactly once, at creation and rotation. A plaintext key_prefix (sk_live_A3F9K2MN) is kept for display so admin UIs can identify a key without the secret.

Authenticating requests

Add api.key ahead of auth:sanctum. A bearer token that does not start with your configured prefix falls straight through to Sanctum, so the same route accepts both kinds of credential.

Inside a controller the resolved key is available for inspection:

Managing keys programmatically

HTTP API

User endpoints (auth:sanctum, default prefix v1/api-keys)

Method & path Action
GET /v1/api-keys List own keys (masked)
POST /v1/api-keys Create key — returns plaintext once
GET /v1/api-keys/{key} Show key detail (never the secret)
PATCH /v1/api-keys/{key} Update name / abilities / rate_limit
POST /v1/api-keys/{key}/rotate Rotate (overlap_minutes, default 0)
DELETE /v1/api-keys/{key} Revoke
GET /v1/api-keys/{key}/usage Usage stats + recent log entries

Admin endpoints (default prefix internal/admin/v1)

Mounted under the boilerplate admin stack (InternalIpWhitelist + auth:sanctum + ability:admin + EnsureAdminAccess when available) when detected, otherwise a minimal auth:sanctum + ability:admin stack. Override with api-keys.admin_route.middleware.

Method & path Action
GET /internal/admin/v1/api-keys List all keys
GET /internal/admin/v1/api-keys/{key} Key detail + usage stats
DELETE /internal/admin/v1/api-keys/{key} Revoke any key
GET /internal/admin/v1/users/{user}/api-keys All keys for a user

Async usage tracking

Usage is recorded in the middleware's terminate() hook via the queued TrackApiKeyUsage job, so it never adds latency to the response. Each request updates the key's aggregate counters (last_used_at, last_used_ip, request_count) and — when api-keys.usage_log.enabled is true — writes a normalized row to api_key_usage_logs (/v1/orders/42 is stored as /v1/orders/{id} to bound cardinality).

Scheduled pruning

Soft-deletes expired keys and deletes usage logs older than api-keys.usage_log.retention_days.

Configuration

See config/api-keys.php — key prefix, allowed environments, token length, user model, default/per-key rate limits, usage-log toggle and retention, queue, max_keys_per_user, and the user/admin route wiring. Every value has an .env override:

Audit events

api_key.created, api_key.revoked, api_key.rotated, api_key.updated, api_key.admin_revoked, api_key.expired. Every event includes key_prefix in its metadata; key_hash and the plaintext key are never logged. Emitted through the host's audit_log() helper when present (no-op otherwise).

Testing

The suite runs standalone via Orchestra Testbench against an in-memory SQLite database with a ULID-keyed test user that mirrors the boilerplate.

License

MIT.


All versions of laravel-api-keys with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/queue Version ^12.0|^13.0
illuminate/cache Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.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 mrsuner/laravel-api-keys contains the following files

Loading the files please wait ...