本文整理匯總了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)