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!: expose GoogleAuth constructor on AuthPlus class #154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
=======================================
Coverage 71.42% 71.42%
=======================================
Files 2 2
Lines 119 119
Branches 38 38
=======================================
Hits 85 85
Misses 16 16
Partials 18 18 Continue to review full report at Codecov.
|
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.
I think I'm just more confused than anything about what's happening here
src/authplus.ts
Outdated
OAuth2Client, | ||
UserRefreshClient, | ||
} from 'google-auth-library'; | ||
import {ProjectIdCallback} from 'google-auth-library/build/src/auth/googleauth'; |
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.
Could I trouble you to go back into google-auth-library, and land a PR to export this properly?
* Override getClient(), memoizing an instance of auth for | ||
* subsequent calls to getProjectId(). | ||
*/ | ||
async getClient( |
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.
Isn't this exactly the kind of thing we want to avoid? Is this a method we would expect end users to consume?
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.
I don't want people to use this method, but I think it's a bit too sweeping to remove the method at this time. Here's why I think this implementation, for the benefit of googlepapis, is a bit better:
- if I call
getClient()
multiple times, the prior call will not have an effect on the values returned by the second call (because anew GoogleAuth()
is created in between). - if I call
getClient(opts); getProjectId(); getClient(); getProjectId()
the cached response from the firstgetClient
won't have an effect on the secondgetProjectId()
.
@@ -20,4 +28,37 @@ export class AuthPlus extends GoogleAuth { | |||
Compute = Compute; | |||
// tslint:disable-next-line: variable-name | |||
OAuth2 = OAuth2Client; | |||
// tslint:disable-next-line: variable-name | |||
GoogleAuth = GoogleAuth; |
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.
So this class extends GoogleAuth
, and we're adding a reference to GoogleAuth
itself? My head is spinnin a bit.
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.
I'm adding a reference to GoogleAuth
, for the same reason that we added Oauth2
, and Compute
, so that we can advertise the approach:
const auth = new google.auth.GoogleAuth(opts);
const client = auth.getClient();
This allows me to advocate this methodology in the README as the safe approach to using the client going forward, also the API surface ends up being more consistent:
const oauth2Client = new google.auth.OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
BREAKING CHANGE: pulls in breaking API changes in google-auth-library.
getProjectId()
andgetProjectId()
have been modified to make the impact of these changes less noticeable on the legacy googleapis module (getClient()
is idempotent, butgetProjectId()
will use the last configuration).At the end of the day, this allows us to avoid updating
cloud.google.com
and a a large number of auto generated samples that follow this format (not to mention stack overflow):I'm hoping this will give us the best of both worlds: