fix: Caching wrong auth token when fetching destination from provider account#6007
Draft
ZhongpinWang wants to merge 7 commits intomainfrom
Draft
fix: Caching wrong auth token when fetching destination from provider account#6007ZhongpinWang wants to merge 7 commits intomainfrom
ZhongpinWang wants to merge 7 commits intomainfrom
Conversation
marikaner
requested changes
Mar 18, 2026
Contributor
marikaner
left a comment
There was a problem hiding this comment.
I don't fully understand the comments, maybe let's talk about them.
Comment on lines
+54
to
+64
| let authTokens: [DestinationAuthToken] | undefined; | ||
| if (validateToken(token)) { | ||
| logger.debug( | ||
| "Option 'forwardAuthToken' enabled on destination. Using the given token for the destination." | ||
| ); | ||
| destination.authTokens = buildDestinationAuthToken(token); | ||
| authTokens = buildDestinationAuthToken(token); | ||
| } | ||
| return { | ||
| ...destination, | ||
| authTokens | ||
| }; |
Contributor
There was a problem hiding this comment.
[pp] I always try to avoid using let and I think here it is easily avoidable.
Suggested change
| let authTokens: [DestinationAuthToken] | undefined; | |
| if (validateToken(token)) { | |
| logger.debug( | |
| "Option 'forwardAuthToken' enabled on destination. Using the given token for the destination." | |
| ); | |
| destination.authTokens = buildDestinationAuthToken(token); | |
| authTokens = buildDestinationAuthToken(token); | |
| } | |
| return { | |
| ...destination, | |
| authTokens | |
| }; | |
| if (validateToken(token)) { | |
| logger.debug( | |
| "Option 'forwardAuthToken' enabled on destination. Using the given token for the destination." | |
| ); | |
| return { | |
| ...destination, | |
| authTokens: buildDestinationAuthToken(token); | |
| } | |
| } |
Comment on lines
114
to
117
| return isHttpDestination(destination) && | ||
| ['internet', 'private-link'].includes(proxyStrategy(destination)) | ||
| ? addProxyConfigurationInternet(destination) | ||
| : destination; |
Contributor
There was a problem hiding this comment.
[pp] For consistency with the new code maybe consider:
Suggested change
| if (isHttpDestination(destination) && | |
| ['internet', 'private-link'].includes(proxyStrategy(destination))) { | |
| destination = addProxyConfigurationInternet(destination); | |
| } | |
| return destination; |
This also applies to the other places where we have the same code.
| // If origin is provider, next time subscriber jwt might change. | ||
| // -> It might be an invalid user jwt next time, and SDK won't throw as destination cached already. | ||
| // -> SDK will use auth token retrieved with the previous subscriber jwt for a different subscriber next time. | ||
| destination = await this.fetchDestinationWithUserExchangeFlows( |
Contributor
There was a problem hiding this comment.
Suggested change
| destination = await this.fetchDestinationWithUserExchangeFlows( | |
| return this.fetchDestinationWithUserExchangeFlows( |
Contributor
There was a problem hiding this comment.
(you can then also remove the elses)
| // then the subdomain of the tenant is sent to destination service and jwt will be exchanged based on the templated token service url. | ||
| // If origin is subscriber | ||
| // -> Auth token can be cached in destination cache as destination is tenant-isolated. | ||
| destination = await this.fetchDestinationWithNonUserExchangeFlows( |
Contributor
There was a problem hiding this comment.
Suggested change
| destination = await this.fetchDestinationWithNonUserExchangeFlows( | |
| return this.fetchDestinationWithNonUserExchangeFlows( |
| // -> Auth token can be cached in destination cache as subscriber is not used. | ||
| // If origin is subscriber, subscriber jwt + refresh token is used. | ||
| // -> Auth token can be cached in destination cache as destination is tenant-isolated. | ||
| destination = await this.fetchDestinationWithRefreshTokenFlow( |
Contributor
There was a problem hiding this comment.
Suggested change
| destination = await this.fetchDestinationWithRefreshTokenFlow( | |
| return this.fetchDestinationWithRefreshTokenFlow( |
| !this.usesSystemUser(destination)) | ||
| ) { | ||
| // VERY BAD... | ||
| // If origin is provider, next time subscriber jwt might change. |
Contributor
There was a problem hiding this comment.
[q] I don't understand this sentence.
Comment on lines
+9
to
+10
| let destination: Destination = { forwardAuthToken: true }; | ||
| destination = addForwardedAuthTokenIfNeeded(destination, jwt); |
Contributor
There was a problem hiding this comment.
Suggested change
| let destination: Destination = { forwardAuthToken: true }; | |
| destination = addForwardedAuthTokenIfNeeded(destination, jwt); | |
| const destination = addForwardedAuthTokenIfNeeded({ forwardAuthToken: true }, jwt); |
Comment on lines
+16
to
+17
| let destination: Destination = {}; | ||
| destination = addForwardedAuthTokenIfNeeded(destination, jwt); |
Contributor
There was a problem hiding this comment.
Suggested change
| let destination: Destination = {}; | |
| destination = addForwardedAuthTokenIfNeeded(destination, jwt); | |
| const destination = addForwardedAuthTokenIfNeeded({}, jwt); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes SAP/cloud-sdk-backlog#1278.