aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/interop/interop_client.php
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-12-10 11:42:55 -0800
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-12-10 11:42:55 -0800
commit3580580367f663c210305c6e5b5fa51f7c724a7d (patch)
tree7946cd82bad8e76f6669a302f61369963fc0b52b /src/php/tests/interop/interop_client.php
parent5a629d39294271230d13cf52c96e7fa49c7df3ca (diff)
php: metadata plugin based auth API
Diffstat (limited to 'src/php/tests/interop/interop_client.php')
-rwxr-xr-xsrc/php/tests/interop/interop_client.php28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 9aab5c966c..45aa8bfc6b 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -84,7 +84,7 @@ function largeUnary($stub)
* @param $fillOauthScope boolean whether to fill result with oauth scope
*/
function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false,
- $metadata = [])
+ $callback = false)
{
$request_len = 271828;
$response_len = 314159;
@@ -99,7 +99,12 @@ function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false
$request->setFillUsername($fillUsername);
$request->setFillOauthScope($fillOauthScope);
- list($result, $status) = $stub->UnaryCall($request, $metadata)->wait();
+ $options = false;
+ if ($callback) {
+ $options['call_credentials_callback'] = $callback;
+ }
+
+ list($result, $status) = $stub->UnaryCall($request, [], $options)->wait();
hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
hardAssert($result !== null, 'Call returned a null response');
$payload = $result->getPayload();
@@ -186,6 +191,13 @@ function oauth2AuthToken($stub, $args)
'invalid email returned');
}
+function updateAuthMetadataCallback($authUri)
+{
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials();
+
+ return $auth_credentials->updateMetadata($metadata = [], $authUri);
+}
+
/**
* Run the per_rpc_creds auth test.
*
@@ -197,15 +209,9 @@ function perRpcCreds($stub, $args)
$jsonKey = json_decode(
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
- $auth_credentials = ApplicationDefaultCredentials::getCredentials(
- $args['oauth_scope']
- );
- $token = $auth_credentials->fetchAuthToken();
- $metadata = [CredentialsLoader::AUTH_METADATA_KEY => [sprintf('%s %s',
- $token['token_type'],
- $token['access_token'])]];
+
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true,
- $metadata);
+ 'updateAuthMetadataCallback');
hardAssert($result->getUsername() == $jsonKey['client_email'],
'invalid email returned');
}
@@ -363,7 +369,7 @@ function cancelAfterFirstResponse($stub)
function timeoutOnSleepingServer($stub)
{
- $call = $stub->FullDuplexCall(['timeout' => 1000]);
+ $call = $stub->FullDuplexCall([], ['timeout' => 1000]);
$request = new grpc\testing\StreamingOutputCallRequest();
$request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
$response_parameters = new grpc\testing\ResponseParameters();