Namespace: credentials

grpc. credentials

Credentials module

This module contains factory methods for two different credential types: CallCredentials and ChannelCredentials. ChannelCredentials are things like SSL credentials that can be used to secure a connection, and are used to construct a Client object. CallCredentials genrally modify metadata, so they can be attached to an individual method call.

CallCredentials can be composed with other CallCredentials to create CallCredentials. ChannelCredentials can be composed with CallCredentials to create ChannelCredentials. No combined credential can have more than one ChannelCredentials.

For example, to create a client secured with SSL that uses Google default application credentials to authenticate:

Example

var channel_creds = credentials.createSsl(root_certs);
(new GoogleAuth()).getApplicationDefault(function(err, credential) {
  var call_creds = credentials.createFromGoogleCredential(credential);
  var combined_creds = credentials.combineChannelCredentials(
      channel_creds, call_creds);
  var client = new Client(address, combined_creds);
});

Classes

CallCredentials
ChannelCredentials

Methods


<static> combineCallCredentials(credentials)

Combine any number of CallCredentials into a single CallCredentials object

Parameters:
Name Type Argument Description
credentials grpc.credentials~CallCredentials <repeatable>

The CallCredentials to compose

Returns:

A credentials object that combines all of the input credentials

Type
grpc.credentials~CallCredentials

<static> combineChannelCredentials(channel_credential, credentials)

Combine a ChannelCredentials with any number of CallCredentials into a single ChannelCredentials object.

Parameters:
Name Type Argument Description
channel_credential grpc.credentials~ChannelCredentials

The ChannelCredentials to start with

credentials grpc.credentials~CallCredentials <repeatable>

The CallCredentials to compose

Returns:

A credentials object that combines all of the input credentials

Type
grpc.credentials~ChannelCredentials

<static> createFromGoogleCredential(google_credential)

Create a gRPC credential from a Google credential object.

Parameters:
Name Type Description
google_credential external:GoogleCredential

The Google credential object to use

Returns:

The resulting credentials object

Type
grpc.credentials~CallCredentials

<static> createFromMetadataGenerator(metadata_generator)

Create a gRPC credentials object from a metadata generation function. This function gets the service URL and a callback as parameters. The error passed to the callback can optionally have a 'code' value attached to it, which corresponds to a status code that this library uses.

Parameters:
Name Type Description
metadata_generator grpc.credentials~generateMetadata

The function that generates metadata

Returns:

The credentials object

Type
grpc.credentials~CallCredentials

<static> createInsecure()

Create an insecure credentials object. This is used to create a channel that does not use SSL. This cannot be composed with anything.

Returns:

The insecure credentials object

Type
grpc.credentials~ChannelCredentials

<static> createSsl( [root_certs] [, private_key] [, cert_chain])

Create an SSL Credentials object. If using a client-side certificate, both the second and third arguments must be passed. Additional peer verification options can be passed in the fourth argument as described below.

Parameters:
Name Type Argument Description
root_certs Buffer <optional>

The root certificate data

private_key Buffer <optional>

The client certificate private key, if applicable

cert_chain Buffer <optional>

The client certificate cert chain, if applicable

verify_options.checkServerIdentity function

Optional callback receiving the expected hostname and peer certificate for additional verification. The callback should return an Error if verification fails and otherwise return undefined.

Returns:

The SSL Credentials object

Type
grpc.credentials~ChannelCredentials

Type Definitions


generateMetadata(params, callback)

Parameters:
Name Type Description
params Object

Parameters that can modify metadata generation

Properties
Name Type Description
service_url string

The URL of the service that the call is going to

callback grpc.credentials~metadataCallback

metadataCallback(error, metadata)

Parameters:
Name Type Description
error Error

The error, if getting metadata failed

metadata grpc.Metadata

The metadata