1313# limitations under the License.
1414
1515"""Authorization support for gRPC."""
16-
16+
1717from __future__ import absolute_import
1818
1919import logging
3131
3232_LOGGER = logging .getLogger (__name__ )
3333
34+
3435class AuthMetadataPlugin (grpc .AuthMetadataPlugin ):
3536 """A `gRPC AuthMetadataPlugin`_ that inserts the credentials into each
3637 request.
@@ -59,13 +60,13 @@ def __init__(self, credentials, request, default_host=None):
5960
6061 def _get_authorization_headers (self , context ):
6162 """Gets the authorization headers for a request.
62-
63+
6364 Returns:
6465 Sequence[Tuple[str, str]]: A list of request headers (key, value)
6566 to add to the request.
6667 """
6768 headers = {}
68-
69+
6970 # https://google.aip.dev/auth/4111
7071 # Attempt to use self-signed JWTs when a service account is used.
7172 # A default host must be explicitly provided since it cannot always
@@ -107,17 +108,17 @@ def secure_authorized_channel(
107108 Users can configure client certificate or rely on device certificates to
108109 establish a mutual TLS channel, if the `GOOGLE_API_USE_CLIENT_CERTIFICATE`
109110 variable is explicitly set to `true`.
110-
111+
111112 Example::
112-
113+
113114 import google.auth
114115 import google.auth.transport.grpc
115116 import google.auth.transport.requests
116117 from google.cloud.speech.v1 import cloud_speech_pb2
117-
118+
118119 # Get credentials.
119120 credentials, _ = google.auth.default()
120-
121+
121122 # Get an HTTP request function to refresh credentials.
122123 request = google.auth.transport.requests.Request()
123124
@@ -186,9 +187,9 @@ def my_client_cert_callback():
186187 endpoint_to_use = regular_endpoint
187188 channel = google.auth.transport.grpc.secure_authorized_channel(
188189 credentials, request, endpoint_to_use,
189- ssl_credentials=default_ssl_credentials)
190+ ssl_credentials=default_ssl_credentials)
190191
191- Option 4: not setting ssl_credentials and client_cert_callback. For devices
192+ Option 4: not setting ssl_credentials and client_cert_callback. For devices
192193 without endpoint verification support or `GOOGLE_API_USE_CLIENT_CERTIFICATE`
193194 environment variable is not `true`, a regular TLS channel is created;
194195 otherwise, a mutual TLS channel is created, however, the call should be
@@ -217,7 +218,7 @@ def my_client_cert_callback():
217218 without using a standard http transport.
218219 target (str): The host and port of the service.
219220 ssl_credentials (grpc.ChannelCredentials): Optional SSL channel
220- credentials. This can be used to specify different certificates.
221+ credentials. This can be used to specify different certificates.
221222 This argument is mutually exclusive with client_cert_callback;
222223 providing both will raise an exception.
223224 If ssl_credentials and client_cert_callback are None, application
@@ -231,7 +232,7 @@ def my_client_cert_callback():
231232 This argument does nothing unless `GOOGLE_API_USE_CLIENT_CERTIFICATE`
232233 environment variable is explicitly set to `true`.
233234 kwargs: Additional arguments to pass to :func:`grpc.secure_channel`.
234-
235+
235236 Returns:
236237 grpc.Channel: The created gRPC channel.
237238
@@ -244,7 +245,7 @@ def my_client_cert_callback():
244245
245246 # Create a set of grpc.CallCredentials using the metadata plugin.
246247 google_auth_credentials = grpc .metadata_call_credentials (metadata_plugin )
247-
248+
248249 if ssl_credentials and client_cert_callback :
249250 raise exceptions .MalformedError (
250251 "Received both ssl_credentials and client_cert_callback; "
0 commit comments