mirror of https://github.com/grpc/grpc-java.git
Update OAuth section in SECURITY.md (#2319)
Replace the deprecated `ClientAuthInterceptor` with `CallCredentials`
This commit is contained in:
parent
7aa0e1a901
commit
e46cb8193f
10
SECURITY.md
10
SECURITY.md
|
|
@ -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);
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue