| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Token; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface; |
| 7 |
/** |
| 8 |
* Interface used to provide interchangeable strategies for adding authorization |
| 9 |
* to requests using the various AWS signature protocols. |
| 10 |
*/ |
| 11 |
class BearerTokenAuthorization implements TokenAuthorization |
| 12 |
{ |
| 13 |
/** |
| 14 |
* Adds the specified token to a request by adding the required headers. |
| 15 |
* |
| 16 |
* @param RequestInterface $request Request to sign |
| 17 |
* @param TokenInterface $token Token |
| 18 |
* |
| 19 |
* @return RequestInterface Returns the modified request. |
| 20 |
*/ |
| 21 |
public function authorizeRequest(RequestInterface $request, TokenInterface $token) |
| 22 |
{ |
| 23 |
if (empty($token) || empty($token->getToken())) { |
| 24 |
throw new InvalidArgumentException("Cannot authorize a request with an empty token"); |
| 25 |
} |
| 26 |
$accessToken = $token->getToken(); |
| 27 |
return $request->withHeader('Authorization', "Bearer {$accessToken}"); |
| 28 |
} |
| 29 |
} |
| 30 |
|