Download the PHP package heinhtet/api-authorizer without Composer

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

Laravel API Authorizer

Latest Version on Packagist Total Downloads

Protect public and internal Laravel APIs with HMAC-SHA256 request signing. Every request must carry a signed set of headers (X-POWERED-BY, X-TIMESTAMP, X-SIGNATURE) that prove the caller is authentic, that the request was not tampered with in transit, and that it is not a replay of a previously captured request.

This package is the reusable, hardened version of an in-app middleware: it fixes the timestamp check, sorts query parameters into the documented canonical order, supports multiple clients with independent secrets, never logs secrets or signatures, and ships with tests and a client-side signer.

Requirements

Installation

Publish the configuration file:

Add the credentials to your .env:

Secrets are per client. Never commit them, never log them, never ship them inside a browser bundle.

Usage

The middleware is registered under the api.authorizer alias. Apply it to the APIs you want to protect.

Or globally for every API route in bootstrap/app.php:

Or on a single route:

Accessing the verified client

Once a request passes verification the resolved client is attached to the request attributes:

Required headers

Header Description Notes
X-POWERED-BY Unique identifier of the frontend client or app Maps to a secret on the server
X-TIMESTAMP Current Unix timestamp in seconds (UTC) Used for replay attack prevention
X-SIGNATURE HMAC-SHA256 of the canonical request Ensures integrity and authenticity
X-REQUEST-ID Optional correlation id for tracing Echoed back in the response, useful for logs

The header names are configurable (see Configuration).

Canonical request format

The signature is computed over this exact string:

Component Rule
METHOD HTTP method, uppercase (GET, POST, PUT, ...)
PATH API path only, e.g. /api/v1/orders — no scheme, host or query string
SORTED_QUERY Query parameters sorted alphabetically by key (then value), joined with &. Empty when none.
TIMESTAMP The same value sent in X-TIMESTAMP
BODY Raw JSON request body for POST/PUT/PATCH/DELETE. Always empty for GET/HEAD.

Example GET with query parameters:

Example POST with a JSON body:

Both client and server must build this string identically. Query parameters may be sent in any order — the package sorts them before signing and before verifying, so status=paid&page=1 and page=1&status=paid produce the same signature.

Signature generation

Worked example, using the secret super-secret-key:

The body is signed byte-for-byte. Send exactly the JSON you signed — the server hashes the raw request body, not a re-serialized copy.

Signing from PHP (server-to-server)

Use the bundled signer, which builds the headers for you:

Or sign an existing request instance:

Signing without this package (any language)

The algorithm is plain HMAC-SHA256 over the canonical string, so any HTTP client can implement it:

curl example

X-TIMESTAMP must be within the allowed window of the server clock. Generate the timestamp and the signature in the same step — a hardcoded pair only works while it is fresh.

Timestamp validation

The client sends a UTC timestamp in seconds. The backend accepts a configurable window (tolerance, default 300 seconds / ±5 minutes) to absorb clock skew and rejects anything outside of it as Request expired. — this is what makes replaying a captured request useless.

Error responses

Rejected requests return HTTP 401 with a JSON envelope:

errors.code status_code (default) Message
missing_header 1001 Missing required headers: X-POWERED-BY, ...
invalid_timestamp 1002 Invalid timestamp.
expired_timestamp 1003 Request expired.
unknown_client 1004 Invalid client.
invalid_signature 1005 Invalid signature.

When an X-REQUEST-ID header is present it is echoed back on both successful and rejected responses so you can correlate client and server logs.

Configuration

The error_codes map lets you align status_code values with your application's own error catalog.

Storing clients in the database

Implement ClientRepositoryInterface and bind it in a service provider to resolve secrets from the database, a cache or a secrets manager instead of the config file:

Development bypass

For local development you can allow a request to skip verification with a shared bypass key:

Keep the bypass disabled in production and store the key in .env only.

Security best practices

Testing

To test your own signed routes, let the package sign the request for you:

Contributing

Please read CONTRIBUTING.md before opening a pull request. Security issues are handled privately as described in SECURITY.md, not in the public issue tracker. Release notes live in CHANGELOG.md.

License

API Authorizer is open-sourced software licensed under the MIT license.


All versions of api-authorizer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^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 heinhtet/api-authorizer contains the following files

Loading the files please wait ...