Search by

juststeveking / http-auth-strategies

JustSteveKing

This package is abandoned and no longer maintained. The author suggests using the juststeveking/sdk-toolbox package instead.

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

Package info

github.com/JustSteveKing/http-auth-strategies

pkg:composer/juststeveking/http-auth-strategies

Fund package maintenance!

JustSteveKing

Statistics

Installs: 72 975

Dependents: 1

Suggesters: 0

Stars: 8

Open Issues: 0

v1.2.0 2020-12-07 12:25 UTC

This package is auto-updated.

Last update: 2026-10-28 19:57:03 UTC


README

Warning

This package is no longer maintained. It's replaced by juststeveking/sdk-toolbox, whose authenticators cover bearer tokens, Basic auth and API keys in a header or the query string, plus OAuth 2.0, with credentials kept out of exceptions and logs.

Existing versions stay installable, so nothing that depends on this package breaks.

Latest Version PHP Version tests Check & fix styling 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']