Skip to content

Commit 676f4f7

Browse files
fix: allow InsecureCredentialsWrapper::getAuthorizationHeaderCallback to return null (#541)
1 parent 58ff20e commit 676f4f7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/InsecureCredentialsWrapper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ public function __construct()
4141
{
4242
}
4343

44-
public function getAuthorizationHeaderCallback($audience = null): callable
44+
/**
45+
* @param string $audience
46+
* @return callable|null Returns null so the gRPC can accept it as an insecure channel.
47+
*/
48+
public function getAuthorizationHeaderCallback($audience = null): ?callable
4549
{
46-
return fn() => [];
50+
return null;
4751
}
4852

4953
public function checkUniverseDomain(): void

src/Transport/HttpUnaryTransportTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ private static function buildCommonHeaders(array $options)
109109
// Prevent unexpected behavior, as the authorization header callback
110110
// uses lowercase "authorization"
111111
unset($headers['authorization']);
112-
$authHeaders = $callback();
112+
// Mitigate scenario where InsecureCredentialsWrapper returns null.
113+
$authHeaders = empty($callback) ? [] : $callback();
113114
if (!is_array($authHeaders)) {
114115
throw new \UnexpectedValueException(
115116
'Expected array response from authorization header callback'

0 commit comments

Comments
 (0)