Skip to main content
Projects / juststeveking/http-auth-strategies

juststeveking/http-auth-strategies

A simple PHP package that is used to create different Http Auth Headers

8
Stars
📦
68.4K
Downloads
📈
947
Monthly

Http Auth Strategies

Latest Version PHP Version

Total Downloads

A simple PHP package that is used to create different Http Auth Headers.

This is a simple to use library, to install - all you need to do is:

$ composer require juststeveking/http-auth-strategies

Then to use the library all you need to do is:

$strategy = new BasicStrategy(
    base64_encode("username:password")
);

// Get the Auth header as an array - passing through the required Authorization prefix
$strategy->getHeader('Bearer');
// ['Authorization' => 'Bearer dXNlcm5hbWU6cGFzc3dvcmQ=']

There is also a NullStrategy for when you want to follow a consistent pattern, but do not want to actually use any auth:

$strategy = new NullStrategy();

// Get the Auth header as an array - passing through the required Authorization prefix
$strategy->getHeader('Bearer');
// []

You can now also create your own custom header using the CustomStrategy, for when an API requires something specific that doesn’t follow the typical pattern:

$strategy = new CustomStrategy(
    'your-api-key'
);

$strategy->setHeaderName('X-API-KEY');

// Get the Auth header as an array - passing through the required Authorization prefix
$strategy->getHeader('Bearer');
// ['X-API-KEY' => 'Bearer your-api-key']
Last updated: 12/5/2025
← Back to all projects
NORMAL
~/projects
command-repl
NORMAL ESC
# Command REPL - Type 'help' for available commands
↑↓ history Tab complete Enter execute
Ctrl+C clear ESC close