Skip to content
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

Improve x-forwarded-authorization header setting logic #3599

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ private String exchangeJWTForPAT(RequestContext requestContext, String pat) thro
if (log.isDebugEnabled()) {
log.debug("Token retrieved from the cache. Token: " + FilterUtils.getMaskedToken(pat));
}
setXForwardedAuthorizationHeader(requestContext, (String) cachedJWT);
return (String) cachedJWT;
}
Optional<String> jwt = APIKeyUtils.exchangePATToJWT(keyHash);
Expand All @@ -828,10 +829,14 @@ private String exchangeJWTForPAT(RequestContext requestContext, String pat) thro
}
CacheProvider.getGatewayAPIKeyJWTCache().put(keyHash, jwt.get());
// Add jwt to x-forwarded-authorization header.
requestContext.addOrModifyHeaders("x-forwarded-authorization", jwt.get());
setXForwardedAuthorizationHeader(requestContext, jwt.get());
return jwt.get();
}

private void setXForwardedAuthorizationHeader(RequestContext requestContext, String jwt) {
requestContext.addOrModifyHeaders("x-forwarded-authorization", String.format("Bearer %s", jwt));
}

public String extractJWTInWSProtocolHeader(RequestContext requestContext) {
String protocolHeader = requestContext.getHeaders().get(
HttpConstants.WEBSOCKET_PROTOCOL_HEADER);
Expand Down
Loading