Update OAuth section in SECURITY.md (#2319)

Replace the deprecated `ClientAuthInterceptor` with `CallCredentials`
This commit is contained in:
ZHANG Dapeng 2016-09-30 14:17:42 -07:00 committed by GitHub
parent 7aa0e1a901
commit e46cb8193f
1 changed files with 5 additions and 5 deletions

View File

@ -302,10 +302,10 @@ ManagedChannel channel = ManagedChannelBuilder.forTarget("pubsub.googleapis.com"
GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
// Down-scope the credential to just the scopes required by the service // Down-scope the credential to just the scopes required by the service
creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub")); creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
// Intercept the channel to bind the credential // Create an instance of {@link io.grpc.CallCredentials}
ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, someExecutor); CallCredentials callCreds = MoreCallCredentials.from(creds);
Channel channel = ClientInterceptors.intercept(channelImpl, interceptor); // Create a stub with credential
// Create a stub using the channel that has the bound credential PublisherGrpc.PublisherBlockingStub publisherStub =
PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel); PublisherGrpc.newBlockingStub(channel).withCallCredentials(callCreds);
publisherStub.publish(someMessage); publisherStub.publish(someMessage);
``` ```