juststeveking / http-auth-strategies
一个简单的PHP包,用于创建不同的Http Auth头
v1.2.0
2020-12-07 12:25 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5@dev
- roave/security-advisories: dev-latest
README
这是一个用于创建不同Http Auth头的简单PHP包。
这是一个易于使用的库,安装 - 您只需做的是
$ composer require juststeveking/http-auth-strategies
然后,要使用这个库,您只需做的是
$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=']
还有一个NullStrategy,当您想要遵循一致的模式但不想实际使用任何认证时
$strategy = new NullStrategy(); // Get the Auth header as an array - passing through the required Authorization prefix $strategy->getHeader('Bearer'); // []
现在您也可以使用CustomStrategy创建自己的自定义头,当API需要特定内容但不遵循典型模式时
$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']