Skip to content

Commit

Permalink
Update API Key implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Apr 8, 2024
1 parent 77948bb commit 4a3d9cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,17 @@ public class APIClient {
authTypes.jwt = {header: <string>jwtAuthentication.headerName, sendTokenToUpstream: <boolean>jwtAuthentication.sendTokenToUpstream, disabled: !jwtAuthentication.enabled, audience: jwtAuthentication.audience};
} else if authentication.authType == "APIKey" && authentication is APIKeyAuthentication {
APIKeyAuthentication apiKeyAuthentication = check authentication.cloneWithType(APIKeyAuthentication);
authTypes.apiKey = [];
authTypes.apiKey.push({'in: "Header", name: apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
authTypes.apiKey.push({'in: "Query", name: apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
model:APIKey[] apiKeys = [];
boolean|() headerEnabled = apiKeyAuthentication.headerEnable;
boolean|() queryEnabled = apiKeyAuthentication.queryParamEnable;

if headerEnabled is boolean && headerEnabled {
apiKeys.push({'in: "Header", name: <string>apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
if queryEnabled is boolean && queryEnabled {
apiKeys.push({'in: "Query", name: <string>apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
authTypes.apiKey = apiKeys;
} else if authentication.authType == "mTLS" {
MTLSAuthentication mtlsAuthentication = check authentication.cloneWithType(MTLSAuthentication);
isMTLSMandatory = mtlsAuthentication.required == "mandatory";
Expand Down
4 changes: 2 additions & 2 deletions runtime/config-deployer-service/ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public type APIKeyAuthentication record {|
boolean sendTokenToUpstream = false;
string headerName = "apiKey";
string queryParamName = "apiKey";
boolean headerEnable = true;
boolean queryParamEnable = true;
boolean headerEnable?;
boolean queryParamEnable?;
|};

# Mutual SSL configuration of this API
Expand Down

0 comments on commit 4a3d9cd

Please sign in to comment.