-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Update google-auth-library
to v10
#1702
Changes from 1 commit
6143377
8a76e3c
65674f9
f1255f3
35c698e
d9622c9
f7eac26
574e7af
2a0079c
195561c
3fd78b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,7 @@ import * as protobuf from 'protobufjs'; | |
import * as gax from './gax'; | ||
import * as routingHeader from './routingHeader'; | ||
import {Status} from './status'; | ||
import { | ||
GoogleAuth, | ||
OAuth2Client, | ||
Compute, | ||
JWT, | ||
UserRefreshClient, | ||
GoogleAuthOptions, | ||
BaseExternalAccountClient, | ||
} from 'google-auth-library'; | ||
import {GoogleAuth, AuthClient} from 'google-auth-library'; | ||
import {OperationsClientBuilder} from './operationsClient'; | ||
import type {GrpcClientOptions, ClientStubOptions} from './grpc'; | ||
import {GaxCall, GRPCCall} from './apitypes'; | ||
|
@@ -85,15 +77,16 @@ export interface ServiceMethods { | |
[name: string]: protobuf.Method; | ||
} | ||
|
||
export type AuthClient = | ||
| OAuth2Client | ||
| Compute | ||
| JWT | ||
| UserRefreshClient | ||
| BaseExternalAccountClient; | ||
/** | ||
* @deprecated use `GoogleAuth` here instead | ||
*/ | ||
type deprecatedAuthClientAlias = AuthClient; | ||
|
||
export class GrpcClient { | ||
auth?: OAuth2Client | GoogleAuth; | ||
auth?: GoogleAuth<AuthClient> | deprecatedAuthClientAlias; | ||
/** | ||
* @deprecated use {@link GrpcClient.auth} instead | ||
*/ | ||
authClient?: AuthClient; | ||
fallback: boolean; | ||
grpcVersion: string; | ||
|
@@ -114,33 +107,36 @@ export class GrpcClient { | |
* gRPC-fallback version of GrpcClient | ||
* Implements GrpcClient API for a browser using grpc-fallback protocol (sends serialized protobuf to HTTP/1 $rpc endpoint). | ||
* | ||
* @param {Object=} options.auth - An instance of OAuth2Client to use in browser, or an instance of GoogleAuth from google-auth-library | ||
* to use in Node.js. Required for browser, optional for Node.js. | ||
* @constructor | ||
* @param options {@link GrpcClientOptions} | ||
*/ | ||
|
||
constructor( | ||
options: (GrpcClientOptions | {auth: OAuth2Client}) & { | ||
options: ( | ||
| GrpcClientOptions | ||
| { | ||
/** | ||
* @deprecated - use `authClient` for `AuthClient`s instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create a follow-up to clean this up in the next major to avoid confusion |
||
*/ | ||
auth: AuthClient; | ||
} | ||
) & { | ||
/** | ||
* Fallback mode to use instead of gRPC. | ||
* A string is accepted for compatibility, all non-empty string values enable the HTTP REST fallback. | ||
*/ | ||
fallback?: boolean | string; | ||
} = {} | ||
) { | ||
if (!isNodeJS()) { | ||
if (!options.auth) { | ||
throw new Error( | ||
JSON.stringify(options) + | ||
'You need to pass auth instance to use gRPC-fallback client in browser or other non-Node.js environments. Use OAuth2Client from google-auth-library.' | ||
); | ||
} | ||
this.auth = options.auth as OAuth2Client; | ||
if (options.auth) { | ||
this.auth = options.auth; | ||
} else if ('authClient' in options) { | ||
this.auth = options.authClient; | ||
} else { | ||
this.auth = | ||
(options.auth as GoogleAuth) || | ||
new GoogleAuth(options as GoogleAuthOptions); | ||
this.auth = new GoogleAuth({ | ||
authClient: options.auth, | ||
...options, | ||
}); | ||
} | ||
|
||
this.fallback = options.fallback ? true : false; | ||
this.grpcVersion = require('../../package.json').version; | ||
this.httpRules = (options as GrpcClientOptions).httpRules; | ||
|
@@ -266,7 +262,7 @@ export class GrpcClient { | |
|
||
/** | ||
* gRPC-fallback version of createStub | ||
* Creates a gRPC-fallback stub with authentication headers built from supplied OAuth2Client instance | ||
* Creates a gRPC-fallback stub with authentication headers built from supplied `AuthClient` instance | ||
* | ||
* @param {function} CreateStub - The constructor function of the stub. | ||
* @param {Object} service - A protobufjs Service object (as returned by lookupService) | ||
|
@@ -284,7 +280,7 @@ export class GrpcClient { | |
) { | ||
if (!this.authClient) { | ||
if (this.auth && 'getClient' in this.auth) { | ||
this.authClient = (await this.auth.getClient()) as AuthClient; | ||
this.authClient = await this.auth.getClient(); | ||
} else if (this.auth && 'getRequestHeaders' in this.auth) { | ||
this.authClient = this.auth; | ||
} | ||
|
@@ -342,7 +338,7 @@ export class GrpcClient { | |
protocol, | ||
servicePath, | ||
servicePort, | ||
this.authClient, | ||
this.auth || this.authClient, | ||
encoder, | ||
decoder, | ||
this.numericEnums, | ||
|
@@ -425,6 +421,7 @@ export function createApiCall( | |
}; | ||
} | ||
if (descriptor && 'streaming' in descriptor && !isNodeJS()) { | ||
// TODO: with `fetch` this is available in the browser... | ||
return () => { | ||
throw new Error( | ||
'Server streaming over the REST transport is only supported in Node.js.' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an auto-repair from
npm