Skip to content

Commit

Permalink
Merge pull request #3595 from mevan-karu/pat_impl_choreo
Browse files Browse the repository at this point in the history
Fix minor issues in PAT flow
  • Loading branch information
renuka-fernando authored Oct 2, 2024
2 parents ee0448f + efa1a69 commit e46b688
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions adapter/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ type upstreamCircuitBreaker struct {
type security struct {
TokenService []tokenService
AuthHeader authHeader
APIKeyConfig apiKeyConfig
PATConfig patConfig
APIKeyConfig apiKeyConfig `toml:"apiKeyConfig"`
PATConfig patConfig `toml:"patConfig"`
}

type authService struct {
Expand Down Expand Up @@ -500,7 +500,7 @@ type authHeader struct {
}

type apiKeyConfig struct {
OAuthAgentURL string
OAuthAgentURL string `toml:"oauthAgentURL"`
}

type patConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public static String generateAPIKeyHash(String apiKey) {
/**
* This function exchanges a given API key to an JWT token.
*
* @param keyHash Key hash
* @return JWT corresponding to given key hash.
* @param pat PAT
* @return JWT corresponding to given PAT.
*/
public static Optional<String> exchangeAPIKeyToJWT(String keyHash) {
public static Optional<String> exchangePATToJWT(String pat) {

URL url = null;
try {
Expand All @@ -115,6 +115,7 @@ public static Optional<String> exchangeAPIKeyToJWT(String keyHash) {
// Create a request to exchange API key to JWT.
HttpPost exchangeRequest = new HttpPost(url.toURI());
exchangeRequest.addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
String keyHash = generateAPIKeyHash(pat);
exchangeRequest.setEntity(new StringEntity(createPATExchangeRequest(keyHash)));
try (CloseableHttpResponse response = httpClient.execute(exchangeRequest)) {
if (response.getStatusLine().getStatusCode() == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ private String exchangeJWTForPAT(String pat) throws APISecurityException {
}
return (String) cachedJWT;
}
Optional<String> jwt = APIKeyUtils.exchangeAPIKeyToJWT(pat);
Optional<String> jwt = APIKeyUtils.exchangePATToJWT(pat);
if (jwt.isEmpty()) {
throw new APISecurityException(APIConstants.StatusCodes.UNAUTHENTICATED.getCode(),
APISecurityConstants.API_AUTH_INVALID_CREDENTIALS,
Expand Down

0 comments on commit e46b688

Please sign in to comment.