0

I've generated my client code from proto files. Now I'm trying to connect but get the 'jwt' is not located at the context error from server. Here's what I do:

$myServiceClient = new MyServiceClient(
    "$host:$port",
    [
        'credentials' => ChannelCredentials::createInsecure(),
        'update_metadata' => function ($metaData) use ($token) {
//            $metaData['authorization'] = ['jwt' . $token]; // doesn't work
//            $metaData['authorization']['jwt'] = $token; // doesn't work
//            $metaData['jwt'] = $token; // doesn't work
            $metaData['authorization'] = ['Bearer ' . $token]; // doesn't work

            return $metaData;
        },
    ]
);
$unaryCall = $myServiceClient->MyMethod(new MyMethodRequest());
$wait = $unaryCall->wait();
anatoly u
  • 69
  • 5

2 Answers2

0

Try this

$myServiceClient = new MyServiceClient(
    "$host:$port",
    [
        'credentials' => ChannelCredentials::createInsecure(),
        'update_metadata' => function ($metaData) use ($token) {
            $metaData['Authorization'] = 'Bearer ' . $token; 
            return $metaData;
        },
    ]
);

Best HTTP Authorization header type for JWT

Or like this:

https://jwt.io/introduction

Authorization: Bearer <token>
hetal
  • 329
  • 2
  • 5
0

The following works for me:

$myServiceClient = new MyServiceClient(
    "$host:$port",
    [
        'credentials' => ChannelCredentials::createInsecure(),
        'update_metadata' => function ($metaData) use ($token) {
            $metaData['jwt'] = [$token];

            return $metaData;
        },
    ]
);
anatoly u
  • 69
  • 5