Repository navigation
AuthorizationHeader
Pair\Http\AuthorizationHeader centralizes parsing for HTTP Authorization headers.
It is shared by Request, OAuth2Token, and the Pair API bootstrap path so Basic and Bearer credentials are read consistently across SAPIs.
Different web servers expose the Authorization header through different PHP variables. Pair checks the common server keys and falls back to apache_request_headers() when available.
This avoids having one auth path read HTTP_AUTHORIZATION while another misses the same request.
Reads the raw Authorization header from the current request environment.
It checks:
AuthorizationHTTP_AUTHORIZATIONREDIRECT_HTTP_AUTHORIZATION-
apache_request_headers()fallback
The returned value is trimmed, and empty values become null.
Reads the raw header from a server-like array. This is useful for tests and for code that wants deterministic input.
$header = \Pair\Http\AuthorizationHeader::fromServer([
'HTTP_AUTHORIZATION' => 'Bearer opaque-token',
]);Extracts a Bearer token case-insensitively.
$token = \Pair\Http\AuthorizationHeader::bearerToken('Bearer opaque-token');The RFC 6750 b64token grammar is enforced. Spaces separate the scheme and token; embedded whitespace and invalid token characters are rejected. The scheme remains case-insensitive.
Extracts Basic credentials from a valid Authorization header.
$credentials = \Pair\Http\AuthorizationHeader::basicCredentials(
'Basic ' . base64_encode('client-id:client-secret')
);The returned array contains:
idsecret
Invalid base64 data, missing separators, and empty IDs or secrets return null. Whitespace inside a decoded credential is significant and is never trimmed. This generic Basic parser does not perform OAuth form decoding: use Pair\Api\OAuth2::clientCredentials() for client_secret_basic.
Request delegates header('Authorization') and bearerToken() to this helper.
OAuth2Token uses the shared raw-header lookup. Its deprecated static parsing facades deliberately preserve historical behavior for frozen callers; use the strict helpers for new endpoints.
- Reading only
$_SERVER['HTTP_AUTHORIZATION']in custom code. - Treating any value after
Beareras valid without checking the standard shape. - Logging raw Authorization headers while debugging authentication failures.
See also: Request, OAuth2Token, ApiController, ApiToken, API.
Maintained by Viames Marino — VM Ingegneria · Professional enquiries
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js, PairMotion.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4