diff options
author | Stanley Cheung <stanleycheung@google.com> | 2015-05-12 17:39:30 -0700 |
---|---|---|
committer | Stanley Cheung <stanleycheung@google.com> | 2015-05-12 22:54:13 -0700 |
commit | f4206872bb00211d67b3170de3360521c9ad5831 (patch) | |
tree | f87d8066079b608014879453fa976b4e7bec11a3 /src/php/lib | |
parent | 07cbf7b4d04041e511c66d8d931eb32e6fc41b45 (diff) |
PHP: add support to pass JWT auth uri to auth library
Diffstat (limited to 'src/php/lib')
-rwxr-xr-x | src/php/lib/Grpc/BaseStub.php | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index cb2537fe98..f9f7d5bb39 100755 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -39,6 +39,7 @@ namespace Grpc; */ class BaseStub { + private $hostname; private $channel; // a callback function @@ -51,6 +52,7 @@ class BaseStub { * metadata array, and returns an updated metadata array */ public function __construct($hostname, $opts) { + $this->hostname = $hostname; $this->update_metadata = null; if (isset($opts['update_metadata'])) { if (is_callable($opts['update_metadata'])) { @@ -69,6 +71,15 @@ class BaseStub { $channel->close(); } + private function _get_jwt_aud_uri($method) { + $last_slash_idx = strrpos($method, '/'); + if ($last_slash_idx === false) { + return false; + } + $service_name = substr($method, 0, $last_slash_idx); + return "https://" . $this->hostname . $service_name; + } + /* This class is intended to be subclassed by generated code, so all functions begin with "_" to avoid name collisions. */ @@ -87,9 +98,11 @@ class BaseStub { $metadata = array()) { $call = new UnaryCall($this->channel, $method, $deserialize); $actual_metadata = $metadata; + $jwt_aud_uri = $this->_get_jwt_aud_uri($method); if (is_callable($this->update_metadata)) { $actual_metadata = call_user_func($this->update_metadata, - $actual_metadata); + $actual_metadata, + $jwt_aud_uri); } $call->start($argument, $actual_metadata); return $call; @@ -112,9 +125,11 @@ class BaseStub { $metadata = array()) { $call = new ClientStreamingCall($this->channel, $method, $deserialize); $actual_metadata = $metadata; + $jwt_aud_uri = $this->_get_jwt_aud_uri($method); if (is_callable($this->update_metadata)) { $actual_metadata = call_user_func($this->update_metadata, - $actual_metadata); + $actual_metadata, + $jwt_aud_uri); } $call->start($arguments, $actual_metadata); return $call; @@ -136,9 +151,11 @@ class BaseStub { $metadata = array()) { $call = new ServerStreamingCall($this->channel, $method, $deserialize); $actual_metadata = $metadata; + $jwt_aud_uri = $this->_get_jwt_aud_uri($method); if (is_callable($this->update_metadata)) { $actual_metadata = call_user_func($this->update_metadata, - $actual_metadata); + $actual_metadata, + $jwt_aud_uri); } $call->start($argument, $actual_metadata); return $call; @@ -157,9 +174,11 @@ class BaseStub { $metadata = array()) { $call = new BidiStreamingCall($this->channel, $method, $deserialize); $actual_metadata = $metadata; + $jwt_aud_uri = $this->_get_jwt_aud_uri($method); if (is_callable($this->update_metadata)) { $actual_metadata = call_user_func($this->update_metadata, - $actual_metadata); + $actual_metadata, + $jwt_aud_uri); } $call->start($actual_metadata); return $call; |