I followed the instructions of generating a Python gPRC client from here but struggle to provide a token to the request
Insecure Channel does not work
auth_creds = grpc.access_token_call_credentials(TOKEN)
channel = grpc.insecure_channel('localhost:10000', auth_creds)
>> TypeError: 'CallCredentials' object is not iterable
Secure Channel does not work either
auth_creds = grpc.access_token_call_credentials(TOKEN)
channel = grpc.secure_channel('localhost:10000', auth_creds)
>> TypeError: Argument 'channel_credentials' has incorrect type (expected grpc._cython.cygrpc.ChannelCredentials, got grpc._cython.cygrpc.MetadataPluginCallCredentials)
According to python gRPC documentation
A CallCredentials has to be used with secure Channel, otherwise the metadata will not be transmitted to the server.
However, how do I create a secure channel, since methods which create these ChannelCredentials correspond to ssl or similar, no?
In addition to that, it seems to be possible to simply parse the tuple {'Authorization':'Bearer <TOKEN>'}
as meta data like here. However, I noticed - as in the comment raised - upper case characters are not allowed.
with_call Method with credentials does not also not work
auth_creds = grpc.access_token_call_credentials(TOKEN)
channel = grpc.secure_channel('localhost:10000', auth_creds)
stub = foo_bar_pb2_grpc.ServiceStub(channel)
response = stub.Get.with_call(message_pb2.Message(), credentials=auth_creds)
>> TypeError: Argument 'channel_credentials' has incorrect type (expected grpc._cython.cygrpc.ChannelCredentials, got grpc._cython.cygrpc.MetadataPluginCallCredentials)
with_call Method with metadata does not also not work
metadata = 'Authorization', 'Bearer <TOKEN>'
channel = grpc.insecure_channel('localhost:10000')
stub = foo_bar_pb2_grpc.ServiceStub(channel)
response = stub.Get.with_call(message_pb2.Message(), metadata=metadata))
>> ValueError: too many values to unpack (expected 2)
Summarized: How do I authenticate my client with an access token?