-
Notifications
You must be signed in to change notification settings - Fork 384
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: simplify return types #407
Conversation
Codecov Report
@@ Coverage Diff @@
## master #407 +/- ##
==========================================
+ Coverage 94.89% 94.96% +0.06%
==========================================
Files 15 15
Lines 960 953 -7
Branches 218 218
==========================================
- Hits 911 905 -6
+ Misses 49 48 -1
Continue to review full report at Codecov.
|
@stephenplusplus for your thoughts too :) |
Possible idea: If we are expecting |
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.
+1 to the suggested changes. The code looks LGTM but it seems like you are awaiting feedback from others as well.
if (callback) { | ||
this.getFederatedSignonCertsAsync() | ||
.then(r => callback(null, r.certs, r.res)) | ||
.then(r => callback(null, r)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Changing the return type is very subtle for users and will be hard for them to debug. I'm -1 on doing this without a rename, but I would be +1 to the suggestion from @kjin. (getter that emits a deprecation warning or maybe throws). |
BREAKING CHANGE: The return types and callbacks for multiple methods have changed. Multiple methods on the
OAuth2
class previously returned a promise that resolved with an object, which contained both the relevant return data and the response object returned from the HTTP request. The data from the HTTP request is not necessary, so the method calls were simplified to only return the relevant data. Affected methods include:OAuth2.getToken()
OAuth2.refreshAccessToken()
OAuth2.getAccessToken()
OAuth2.getRequestMetadata()
OAuth2.getFederatedSignonCerts()
JWTAccess.getRequestMetadata()
For example:
Old code
New code
A note for the readers: it's possible this is a bad idea. I am trying to do a couple of things here:
axios
orrequest
specific behaviors.I am a little concerned because these changes change the return type with practically no warning, even though this is semver major. An alternative approach could be:
OAuth2.getToken()
- Introduce a newOAuth2.getTokens()
method with the new return type, and update the docs and samples. Deprecate thegetToken
method, and delete it in 3.0. The namegetToken
is funny, since we return multiple tokens in many cases.OAuth2.refreshAccessToken
- Deprecate it, and delete it in 3.0. This method is already marked asdeprecated
in the jsdocs.OAuth2.getAccessToken
- I got nothin. The object return type as it is today is just weird and unexpected, but I don't know how to nuance a fix.OAuth2.getRequestMetadata()
- Introduce agetAuthorizationHeader
method that returns a string with the Authorization header. Deprecate this method, decom in 3.0. I always thought this method was weird, since all it does is return a map with a single header value set. This forces users toObject.assign
against other headers, instead of letting them just saymyheaders.Authorization = client.getAuthorizationHeader()
.OAuth2.getFederatedSignonCerts()
- I have no idea why in the world this is a public method. We should just deprecate, and make private in 3.0.I honestly don't know if all the churn above is really worth it, but I want to hear other opinions here :)