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:
- Source:
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
Methods
(static) combineCallCredentials(…credentials)
Combine any number of CallCredentials into a single CallCredentials object
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
credentials |
CallCredentials |
<repeatable> |
the CallCredentials to compose |
- Source:
Returns:
CallCredentials A credentials object that combines all of the input credentials
(static) combineChannelCredentials(channel_credential, …credentials)
Combine a ChannelCredentials with any number of CallCredentials into a single ChannelCredentials object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
channel_credential |
ChannelCredentials | The ChannelCredentials to start with |
|
credentials |
CallCredentials |
<repeatable> |
The CallCredentials to compose |
- Source:
Returns:
ChannelCredentials A credentials object that combines all of the input credentials
(static) createFromGoogleCredential(google_credential) → {grpc.credentials.CallCredentials}
Create a gRPC credential from a Google credential object.
Parameters:
| Name | Type | Description |
|---|---|---|
google_credential |
external:GoogleCredential | The Google credential object to use |
- Source:
Returns:
The resulting credentials object
- Type
- grpc.credentials.CallCredentials
(static) createFromMetadataGenerator(metadata_generator) → {grpc.credentials.CallCredentials}
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 |
- Source:
Returns:
The credentials object
- Type
- grpc.credentials.CallCredentials
(static) createInsecure() → {ChannelCredentials}
Create an insecure credentials object. This is used to create a channel that does not use SSL. This cannot be composed with anything.
- Source:
Returns:
The insecure credentials object
- Type
- ChannelCredentials
(static) createSsl(root_certs, private_keyopt, cert_chainopt) → {grpc.credentials.ChannelCredentials}
Create an SSL Credentials object. If using a client-side certificate, both the second and third arguments must be passed.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
root_certs |
Buffer | 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 |
- Source:
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
|
||||||
callback |
grpc.credentials~metadataCallback |
- Source:
metadataCallback(error, metadata)
Parameters:
| Name | Type | Description |
|---|---|---|
error |
Error | The error, if getting metadata failed |
metadata |
grpc.Metadata | The metadata |
- Source: