UNPKG

2.42 kBTypeScriptView Raw
1import { Metadata } from './metadata';
2export interface CallMetadataOptions {
3 service_url: string;
4}
5export declare type CallMetadataGenerator = (options: CallMetadataOptions, cb: (err: Error | null, metadata?: Metadata) => void) => void;
6export interface OldOAuth2Client {
7 getRequestMetadata: (url: string, callback: (err: Error | null, headers?: {
8 [index: string]: string;
9 }) => void) => void;
10}
11export interface CurrentOAuth2Client {
12 getRequestHeaders: (url?: string) => Promise<{
13 [index: string]: string;
14 }>;
15}
16export declare type OAuth2Client = OldOAuth2Client | CurrentOAuth2Client;
17/**
18 * A class that represents a generic method of adding authentication-related
19 * metadata on a per-request basis.
20 */
21export declare abstract class CallCredentials {
22 /**
23 * Asynchronously generates a new Metadata object.
24 * @param options Options used in generating the Metadata object.
25 */
26 abstract generateMetadata(options: CallMetadataOptions): Promise<Metadata>;
27 /**
28 * Creates a new CallCredentials object from properties of both this and
29 * another CallCredentials object. This object's metadata generator will be
30 * called first.
31 * @param callCredentials The other CallCredentials object.
32 */
33 abstract compose(callCredentials: CallCredentials): CallCredentials;
34 /**
35 * Check whether two call credentials objects are equal. Separate
36 * SingleCallCredentials with identical metadata generator functions are
37 * equal.
38 * @param other The other CallCredentials object to compare with.
39 */
40 abstract _equals(other: CallCredentials): boolean;
41 /**
42 * Creates a new CallCredentials object from a given function that generates
43 * Metadata objects.
44 * @param metadataGenerator A function that accepts a set of options, and
45 * generates a Metadata object based on these options, which is passed back
46 * to the caller via a supplied (err, metadata) callback.
47 */
48 static createFromMetadataGenerator(metadataGenerator: CallMetadataGenerator): CallCredentials;
49 /**
50 * Create a gRPC credential from a Google credential object.
51 * @param googleCredentials The authentication client to use.
52 * @return The resulting CallCredentials object.
53 */
54 static createFromGoogleCredential(googleCredentials: OAuth2Client): CallCredentials;
55 static createEmpty(): CallCredentials;
56}