google.auth.transport.grpc module¶
Authorization support for gRPC.
-
class
AuthMetadataPlugin
(credentials, request)[source]¶ Bases:
grpc.AuthMetadataPlugin
A gRPC AuthMetadataPlugin that inserts the credentials into each request.
- Parameters
credentials (google.auth.credentials.Credentials) – The credentials to add to requests.
request (google.auth.transport.Request) – A HTTP transport request object used to refresh credentials as needed.
Creates a secure authorized gRPC channel.
This creates a channel with SSL and
AuthMetadataPlugin
. This channel can be used to create a stub that can make authorized requests.Example:
import google.auth import google.auth.transport.grpc import google.auth.transport.requests from google.cloud.speech.v1 import cloud_speech_pb2 # Get credentials. credentials, _ = google.auth.default() # Get an HTTP request function to refresh credentials. request = google.auth.transport.requests.Request() # Create a channel. channel = google.auth.transport.grpc.secure_authorized_channel( credentials, 'speech.googleapis.com:443', request) # Use the channel to create a stub. cloud_speech.create_Speech_stub(channel)
- Parameters
credentials (google.auth.credentials.Credentials) – The credentials to add to requests.
request (google.auth.transport.Request) – A HTTP transport request object used to refresh credentials as needed. Even though gRPC is a separate transport, there’s no way to refresh the credentials without using a standard http transport.
target (str) – The host and port of the service.
ssl_credentials (grpc.ChannelCredentials) – Optional SSL channel credentials. This can be used to specify different certificates.
kwargs – Additional arguments to pass to
grpc.secure_channel()
.
- Returns
The created gRPC channel.
- Return type
grpc.Channel