Mise à jour des librairies vendor

This commit is contained in:
Caribana
2018-05-01 14:43:32 +02:00
parent b67375ae8e
commit d776be73fc
5211 changed files with 59115 additions and 25863 deletions

View File

@@ -86,7 +86,7 @@ class ApplicationDefaultCredentials
) {
$creds = self::getCredentials($scope, $httpHandler, $cacheConfig, $cache);
return new AuthTokenSubscriber($creds, $cacheConfig);
return new AuthTokenSubscriber($creds, $httpHandler);
}
/**
@@ -114,7 +114,7 @@ class ApplicationDefaultCredentials
) {
$creds = self::getCredentials($scope, $httpHandler, $cacheConfig, $cache);
return new AuthTokenMiddleware($creds, $cacheConfig);
return new AuthTokenMiddleware($creds, $httpHandler);
}
/**

View File

@@ -134,7 +134,7 @@ final class Item implements CacheItemInterface
} else {
$message = 'Argument 1 passed to %s::expiresAfter() must be an ' .
'instance of DateInterval or of the type integer, %s given';
$error = sprintf($message, get_class($this), gettype($expiration));
$error = sprintf($message, get_class($this), gettype($time));
$this->handleError($error);
}

View File

@@ -51,7 +51,6 @@ final class MemoryCacheItemPool implements CacheItemPoolInterface
$items = [];
foreach ($keys as $key) {
$this->isValidKey($key);
$items[$key] = $this->hasItem($key) ? clone $this->items[$key] : new Item($key);
}
@@ -74,7 +73,7 @@ final class MemoryCacheItemPool implements CacheItemPoolInterface
public function clear()
{
$this->items = [];
$this->deferred = [];
$this->deferredItems = [];
return true;
}

View File

@@ -19,6 +19,8 @@ namespace Google\Auth;
trait CacheTrait
{
private $maxKeyLength = 64;
/**
* Gets the cached value if it is present in the cache when that is
* available.
@@ -35,7 +37,9 @@ trait CacheTrait
}
$cacheItem = $this->cache->getItem($key);
return $cacheItem->get();
if ($cacheItem->isHit()) {
return $cacheItem->get();
}
}
/**
@@ -67,6 +71,13 @@ trait CacheTrait
$key = $this->cacheConfig['prefix'] . $key;
// ensure we do not have illegal characters
return preg_replace('|[^a-zA-Z0-9_\.!]|', '', $key);
$key = preg_replace('|[^a-zA-Z0-9_\.!]|', '', $key);
// Hash keys if they exceed $maxKeyLength (defaults to 64)
if ($this->maxKeyLength && strlen($key) > $this->maxKeyLength) {
$key = substr(hash('sha256', $key), 0, $this->maxKeyLength);
}
return $key;
}
}

View File

@@ -69,15 +69,25 @@ class AppIdentityCredentials extends CredentialsLoader
}
/**
* Determines if this an App Engine instance, by accessing the SERVER_SOFTWARE
* environment variable.
* Determines if this an App Engine instance, by accessing the
* SERVER_SOFTWARE environment variable (prod) or the APPENGINE_RUNTIME
* environment variable (dev).
*
* @return true if this an App Engine Instance, false otherwise
*/
public static function onAppEngine()
{
return isset($_SERVER['SERVER_SOFTWARE']) &&
strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') !== false;
$appEngineProduction = isset($_SERVER['SERVER_SOFTWARE']) &&
0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine');
if ($appEngineProduction) {
return true;
}
$appEngineDevAppServer = isset($_SERVER['APPENGINE_RUNTIME']) &&
$_SERVER['APPENGINE_RUNTIME'] == 'php';
if ($appEngineDevAppServer) {
return true;
}
return false;
}
/**

View File

@@ -102,13 +102,13 @@ class GCECredentials extends CredentialsLoader
/**
* Determines if this an App Engine Flexible instance, by accessing the
* GAE_VM environment variable.
* GAE_INSTANCE environment variable.
*
* @return true if this an App Engine Flexible Instance, false otherwise
*/
public static function onAppEngineFlexible()
{
return isset($_SERVER['GAE_VM']) && 'true' === $_SERVER['GAE_VM'];
return substr(getenv('GAE_INSTANCE'), 0, 4) === 'aef-';
}
/**

View File

@@ -30,7 +30,7 @@ abstract class CredentialsLoader implements FetchAuthTokenInterface
const ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS';
const WELL_KNOWN_PATH = 'gcloud/application_default_credentials.json';
const NON_WINDOWS_WELL_KNOWN_PATH_BASE = '.config';
const AUTH_METADATA_KEY = 'Authorization';
const AUTH_METADATA_KEY = 'authorization';
/**
* @param string $cause
@@ -106,7 +106,7 @@ abstract class CredentialsLoader implements FetchAuthTokenInterface
/**
* Create a new Credentials instance.
*
* @param string|array scope the scope of the access request, expressed
* @param string|array $scope the scope of the access request, expressed
* either as an Array or as a space-delimited String.
* @param array $jsonKey the JSON credentials.
*
@@ -127,6 +127,53 @@ abstract class CredentialsLoader implements FetchAuthTokenInterface
}
}
/**
* Create an authorized HTTP Client from an instance of FetchAuthTokenInterface.
*
* @param FetchAuthTokenInterface $fetcher is used to fetch the auth token
* @param array $httpClientOptoins (optional) Array of request options to apply.
* @param callable $httpHandler (optional) http client to fetch the token.
* @param callable $tokenCallback (optional) function to be called when a new token is fetched.
*
* @return \GuzzleHttp\Client
*/
public static function makeHttpClient(
FetchAuthTokenInterface $fetcher,
array $httpClientOptions = [],
callable $httpHandler = null,
callable $tokenCallback = null
) {
$version = \GuzzleHttp\ClientInterface::VERSION;
switch ($version[0]) {
case '5':
$client = new \GuzzleHttp\Client($httpClientOptions);
$client->setDefaultOption('auth', 'google_auth');
$subscriber = new Subscriber\AuthTokenSubscriber(
$fetcher,
$httpHandler,
$tokenCallback
);
$client->getEmitter()->attach($subscriber);
return $client;
case '6':
$middleware = new Middleware\AuthTokenMiddleware(
$fetcher,
$httpHandler,
$tokenCallback
);
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push($middleware);
return new \GuzzleHttp\Client([
'handler' => $stack,
'auth' => 'google_auth',
] + $httpClientOptions);
default:
throw new \Exception('Version not supported');
}
}
/**
* export a callback function which updates runtime metadata.
*

View File

@@ -16,7 +16,11 @@
*/
namespace Google\Auth\HttpHandler;
use Exception;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Message\ResponseInterface as Guzzle5ResponseInterface;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\RejectedPromise;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -46,17 +50,73 @@ class Guzzle5HttpHandler
*/
public function __invoke(RequestInterface $request, array $options = [])
{
$request = $this->client->createRequest(
$response = $this->client->send(
$this->createGuzzle5Request($request, $options)
);
return $this->createPsr7Response($response);
}
/**
* Accepts a PSR-7 request and an array of options and returns a PromiseInterface
*
* @param RequestInterface $request
* @param array $options
*
* @return Promise
*/
public function async(RequestInterface $request, array $options = [])
{
if (!class_exists('GuzzleHttp\Promise\Promise')) {
throw new Exception('Install guzzlehttp/promises to use async with Guzzle 5');
}
$futureResponse = $this->client->send(
$this->createGuzzle5Request(
$request,
['future' => true] + $options
)
);
$promise = new Promise(
function () use ($futureResponse) {
try {
$futureResponse->wait();
} catch (Exception $e) {
// The promise is already delivered when the exception is
// thrown, so don't rethrow it.
}
},
[$futureResponse, 'cancel']
);
$futureResponse->then([$promise, 'resolve'], [$promise, 'reject']);
return $promise->then(
function (Guzzle5ResponseInterface $response) {
// Adapt the Guzzle 5 Response to a PSR-7 Response.
return $this->createPsr7Response($response);
},
function (Exception $e) {
return new RejectedPromise($e);
}
);
}
private function createGuzzle5Request(RequestInterface $request, array $options)
{
return $this->client->createRequest(
$request->getMethod(),
$request->getUri(),
array_merge([
array_merge_recursive([
'headers' => $request->getHeaders(),
'body' => $request->getBody(),
], $options)
);
}
$response = $this->client->send($request);
private function createPsr7Response(Guzzle5ResponseInterface $response)
{
return new Response(
$response->getStatusCode(),
$response->getHeaders() ?: [],

View File

@@ -33,4 +33,17 @@ class Guzzle6HttpHandler
{
return $this->client->send($request, $options);
}
/**
* Accepts a PSR-7 request and an array of options and returns a PromiseInterface
*
* @param RequestInterface $request
* @param array $options
*
* @return \GuzzleHttp\Promise\Promise
*/
public function async(RequestInterface $request, array $options = [])
{
return $this->client->sendAsync($request, $options);
}
}

View File

@@ -29,7 +29,7 @@ use Psr\Http\Message\RequestInterface;
*
* Requests will be accessed with the authorization header:
*
* 'Authorization' 'Bearer <value of auth_token>'
* 'authorization' 'Bearer <value of auth_token>'
*/
class AuthTokenMiddleware
{
@@ -99,7 +99,7 @@ class AuthTokenMiddleware
return $handler($request, $options);
}
$request = $request->withHeader('Authorization', 'Bearer ' . $this->fetchToken());
$request = $request->withHeader('authorization', 'Bearer ' . $this->fetchToken());
return $handler($request, $options);
};

View File

@@ -31,7 +31,7 @@ use Psr\Http\Message\RequestInterface;
*
* Requests will be accessed with the authorization header:
*
* 'Authorization' 'Bearer <value of auth_token>'
* 'authorization' 'Bearer <value of auth_token>'
*/
class ScopedAccessTokenMiddleware
{
@@ -113,7 +113,7 @@ class ScopedAccessTokenMiddleware
* $client = new Client([
* 'handler' => $stack,
* 'base_url' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/',
* 'auth' => 'google_auth' // authorize all requests
* 'auth' => 'scoped' // authorize all requests
* ]);
*
* $res = $client->get('myproject/taskqueues/myqueue');
@@ -130,7 +130,7 @@ class ScopedAccessTokenMiddleware
return $handler($request, $options);
}
$request = $request->withHeader('Authorization', 'Bearer ' . $this->fetchToken());
$request = $request->withHeader('authorization', 'Bearer ' . $this->fetchToken());
return $handler($request, $options);
};

View File

@@ -238,6 +238,12 @@ class OAuth2 implements FetchAuthTokenInterface
*/
private $extensionParams;
/**
* When using the toJwt function, these claims will be added to the JWT
* payload.
*/
private $additionalClaims;
/**
* Create a new OAuthCredentials.
*
@@ -322,6 +328,7 @@ class OAuth2 implements FetchAuthTokenInterface
'signingKey' => null,
'signingAlgorithm' => null,
'scope' => null,
'additionalClaims' => [],
], $config);
$this->setAuthorizationUri($opts['authorizationUri']);
@@ -340,6 +347,7 @@ class OAuth2 implements FetchAuthTokenInterface
$this->setSigningAlgorithm($opts['signingAlgorithm']);
$this->setScope($opts['scope']);
$this->setExtensionParams($opts['extensionParams']);
$this->setAdditionalClaims($opts['additionalClaims']);
$this->updateToken($opts);
}
@@ -413,6 +421,7 @@ class OAuth2 implements FetchAuthTokenInterface
if (!(is_null($this->getSub()))) {
$assertion['sub'] = $this->getSub();
}
$assertion += $this->getAdditionalClaims();
return $this->jwtEncode($assertion, $this->getSigningKey(),
$this->getSigningAlgorithm());
@@ -1212,6 +1221,26 @@ class OAuth2 implements FetchAuthTokenInterface
$this->refreshToken = $refreshToken;
}
/**
* Sets additional claims to be included in the JWT token
*
* @param array $additionalClaims
*/
public function setAdditionalClaims(array $additionalClaims)
{
$this->additionalClaims = $additionalClaims;
}
/**
* Gets the additional claims to be included in the JWT token.
*
* @return array
*/
public function getAdditionalClaims()
{
return $this->additionalClaims;
}
/**
* The expiration of the last received token.
*

View File

@@ -31,7 +31,7 @@ use GuzzleHttp\Event\SubscriberInterface;
*
* Requests will be accessed with the authorization header:
*
* 'Authorization' 'Bearer <value of auth_token>'
* 'authorization' 'Bearer <value of auth_token>'
*/
class AuthTokenSubscriber implements SubscriberInterface
{
@@ -107,7 +107,7 @@ class AuthTokenSubscriber implements SubscriberInterface
// Fetch the auth token.
$auth_tokens = $this->fetcher->fetchAuthToken($this->httpHandler);
if (array_key_exists('access_token', $auth_tokens)) {
$request->setHeader('Authorization', 'Bearer ' . $auth_tokens['access_token']);
$request->setHeader('authorization', 'Bearer ' . $auth_tokens['access_token']);
// notify the callback if applicable
if ($this->tokenCallback) {

View File

@@ -33,7 +33,7 @@ use Psr\Cache\CacheItemPoolInterface;
*
* Requests will be accessed with the authorization header:
*
* 'Authorization' 'Bearer <access token obtained from the closure>'
* 'authorization' 'Bearer <access token obtained from the closure>'
*/
class ScopedAccessTokenSubscriber implements SubscriberInterface
{
@@ -135,7 +135,7 @@ class ScopedAccessTokenSubscriber implements SubscriberInterface
return;
}
$auth_header = 'Bearer ' . $this->fetchToken();
$request->setHeader('Authorization', $auth_header);
$request->setHeader('authorization', $auth_header);
}
/**