What is the right way of passing the call credentials when using an
insecure channel?
I have this client code:
channel = grpc.insecure_channel('localhost:50051')
stub = snippets_pb2_grpc.SnippetsStub(channel)
request = snippets_pb2.SnippetsRequest()
code_snippets = stub.GetAllSnippets(
request,
credentials=access_token_call_credentials('my_token')
)
With this, I can't access provided credentials on the server side. Tried
both: *context.auth_content()* (returns empty dict) and
*context.invocation_metadata()* (doesn't have any token keys).
With the same result I've also tried to extend the *grpc.AuthMetadataPlugin
*class and work this way:
class UsernamePasswordCallCredentials(grpc.AuthMetadataPlugin):
"""Metadata wrapper for raw access token credentials."""
def __init__(self, username, password):
self._username = username
self._password = password
def __call__(self, context, callback):
basic_auth = "Basic %s" % base64.b64encode("%s:%s" %
(self._username, self._password))
metadata = (('authorization', basic_auth),)
callback(metadata, None)
call_creds =
metadata_call_credentials(UsernamePasswordCallCredentials('my_name',
'my_password'))
channel = grpc.insecure_channel('localhost:50051')
stub = snippets_pb2_grpc.SnippetsStub(channel)
request = snippets_pb2.SnippetsRequest()
code_snippets = stub.GetAllSnippets(
request,
credentials=call_creds
)
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/83c57d08-50e3-4333-a53d-36921da2add1%40googlegroups.com.