本文整理汇总了Python中grpc.AuthMetadataContext方法的典型用法代码示例。如果您正苦于以下问题:Python grpc.AuthMetadataContext方法的具体用法?Python grpc.AuthMetadataContext怎么用?Python grpc.AuthMetadataContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grpc
的用法示例。
在下文中一共展示了grpc.AuthMetadataContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import AuthMetadataContext [as 别名]
def __call__(self, context, callback):
"""Passes authorization metadata into the given callback.
Args:
context (grpc.AuthMetadataContext): The RPC context.
callback (grpc.AuthMetadataPluginCallback): The callback that will
be invoked to pass in the authorization metadata.
"""
headers = {}
self._credentials.before_request(
self._request, context.method_name, context.service_url, headers
)
id_token = getattr(self._credentials, "id_token", None)
if id_token:
self._credentials.apply(headers, token=id_token)
else:
logger.error("Failed to find ID token credentials")
# Pass headers as key-value pairs to match CallCredentials metadata.
callback(list(headers.items()), None)
示例2: test_call_no_refresh
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import AuthMetadataContext [as 别名]
def test_call_no_refresh(self):
credentials = CredentialsStub()
request = mock.create_autospec(transport.Request)
plugin = google.auth.transport.grpc.AuthMetadataPlugin(credentials, request)
context = mock.create_autospec(grpc.AuthMetadataContext, instance=True)
context.method_name = mock.sentinel.method_name
context.service_url = mock.sentinel.service_url
callback = mock.create_autospec(grpc.AuthMetadataPluginCallback)
plugin(context, callback)
time.sleep(2)
callback.assert_called_once_with(
[(u"authorization", u"Bearer {}".format(credentials.token))], None
)
示例3: test_call_refresh
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import AuthMetadataContext [as 别名]
def test_call_refresh(self):
credentials = CredentialsStub()
credentials.expiry = datetime.datetime.min + _helpers.CLOCK_SKEW
request = mock.create_autospec(transport.Request)
plugin = google.auth.transport.grpc.AuthMetadataPlugin(credentials, request)
context = mock.create_autospec(grpc.AuthMetadataContext, instance=True)
context.method_name = mock.sentinel.method_name
context.service_url = mock.sentinel.service_url
callback = mock.create_autospec(grpc.AuthMetadataPluginCallback)
plugin(context, callback)
time.sleep(2)
assert credentials.token == "token1"
callback.assert_called_once_with(
[(u"authorization", u"Bearer {}".format(credentials.token))], None
)
示例4: __call__
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import AuthMetadataContext [as 别名]
def __call__(self, context, callback):
"""Passes authorization metadata into the given callback.
Args:
context (grpc.AuthMetadataContext): The RPC context.
callback (grpc.AuthMetadataPluginCallback): The callback that will
be invoked to pass in the authorization metadata.
"""
callback(self._get_authorization_headers(context), None)