14 """Client of the Python example of customizing authentication mechanism."""
23 helloworld_pb2, helloworld_pb2_grpc = grpc.protos_and_services(
26 _LOGGER = logging.getLogger(__name__)
27 _LOGGER.setLevel(logging.INFO)
29 _SERVER_ADDR_TEMPLATE =
'localhost:%d'
30 _SIGNATURE_HEADER_KEY =
'x-signature'
36 """Implements authentication by passing metadata to a callback.
38 Implementations of this method must not block.
41 context: An AuthMetadataContext providing information on the RPC that
42 the plugin is being called to authenticate.
43 callback: An AuthMetadataPluginCallback to be invoked either
44 synchronously or asynchronously.
50 signature = context.method_name[::-1]
51 callback(((_SIGNATURE_HEADER_KEY, signature),),
None)
54 @contextlib.contextmanager
61 _credentials.ROOT_CERTIFICATE)
75 response = stub.SayHello(request)
77 _LOGGER.error(
'Received error: %s', rpc_error)
80 _LOGGER.info(
'Received message: %s', response)
85 parser = argparse.ArgumentParser()
86 parser.add_argument(
'--port',
90 help=
'the address of server')
91 args = parser.parse_args()
97 if __name__ ==
'__main__':
98 logging.basicConfig(level=logging.INFO)