fix(oauth): bubble up new token when refreshing it #1163
+50
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes
AuthInfo.refreshFn
passing the expired access token instead of the new fresh one when refreshing the session.Others:
Org/Connection
refreshAuth do a HEAD request (small improvement)Context
sfdx-core sets a custom refreshFn for oauth refresh (jsforce has a default one but ours also updates the AuthInfo instance with the new token):
sfdx-core/src/org/authInfo.ts
Line 644 in 0919f28
sfdx-core/src/org/authInfo.ts
Line 942 in 0919f28
jsforce calls it here, expecting the callback to send back the new, refreshed token to set it in the
Connection
instance:https://github.com/jsforce/jsforce/blob/73a6d0a174050b370b4248925e2e474bba27091d/src/session-refresh-delegate.ts#L53
AuthInfo.refreshFn
was getting a new access token when callingthis.initAuthOptions
here:https://github.com/forcedotcom/sfdx-core/blob/0919f2844544983b7635f9d25eb544c2f4aa7cdd/src/org/authInfo.ts#L949C1-L952C55
but it was sending back the expired access token from the previously decrypted auth fields to the callback, causing 2 refresh calls every time sfdx-core was doing a request with an expired token.
See the following examples, we expire the current token and call
api request reset
(with this PR linked: salesforcecli/plugin-api#62) which tries to refresh the token before doing thelimits
call withgot
.`AuthInfo.refreshFn` passes the expired AT to the callback, fires an additional refresh
`AuthInfo.refreshFn` passes the new AT to the callback, next request uses it successfully
Testing
See repro steps in plugin-api PR ⬆️
With both PRs you should see only one refresh call when running
api request rest
with an expired token.What issues does this PR fix or reference?
forcedotcom/cli#3176
@W-17605467@