This package is abandoned and no longer maintained. No replacement package was suggested.

Guzzle Bearer plugin

0.2.2 2014-01-15 16:17 UTC

This package is not auto-updated.

Last update: 2019-02-20 17:29:42 UTC


This is a Guzzle plugin to support Bearer Authentication as specified in RFC 6750.

Example Use

require_once 'vendor/autoload.php';

use Guzzle\Http\Client;
use fkooman\Guzzle\Plugin\BearerAuth\BearerAuth;
use fkooman\Guzzle\Plugin\BearerAuth\Exception\BearerErrorResponseException;
use Guzzle\Http\Exception\BadResponseException;

try {
    $client = new Client();

    $bearerAuth = new BearerAuth("12345");
    $response = $client->get('')->send();
    echo $response->getBody();
} catch (BearerErrorResponseException $e) {
    echo $e->getMessage() . PHP_EOL;
} catch (BadResponseException $e) {
    echo $e->getMessage() . PHP_EOL;


The BearerErrorResponseException can be used to figure out what went wrong with the Bearer authentication. The reason is available using getBearerReason(). The values are defined in RFC 6750 section 3.1, so either invalid_request, invalid_token or insufficient_scope. You can use this to figure out what went wrong and e.g. remove the access token from your storage or mark it as unusable.