Skip to content

Commit

Permalink
Merge pull request #2323 from sgayangi/api-key
Browse files Browse the repository at this point in the history
Update API Key implementation
  • Loading branch information
CrowleyRajapakse authored May 7, 2024
2 parents 6d3ae4b + cc44f9b commit 7842cf5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
12 changes: 9 additions & 3 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,15 @@ 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 = [];

if apiKeyAuthentication.headerEnable {
apiKeys.push({'in: "Header", name: <string>apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
if apiKeyAuthentication.queryParamEnable {
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ components:
headerEnable:
type: boolean
default: true
audience:
audience:
type: array
default: []
items:
Expand All @@ -173,7 +173,7 @@ components:
default: false
headerName:
type: string
example: Authorization
example: apikey
default: apikey
queryParamName:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
},
"headerName": {
"type": "string",
"example": "Authorization",
"example": "apikey",
"default": "apikey"
},
"queryParamName": {
Expand Down
2 changes: 1 addition & 1 deletion runtime/config-deployer-service/ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public type APIKeyAuthentication record {|
string headerName = "apiKey";
string queryParamName = "apiKey";
boolean headerEnable = true;
boolean queryParamEnable = true;
boolean queryParamEnable = false;
|};

# Mutual SSL configuration of this API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,16 @@
"required": {
"type": "string",
"default": "mandatory",
"enum": ["mandatory", "optional"]
"enum": [
"mandatory",
"optional"
]
},
"authType": {
"type": "string",
"enum": ["JWT"]
"enum": [
"JWT"
]
},
"sendTokenToUpstream": {
"type": "boolean",
Expand Down Expand Up @@ -253,7 +258,7 @@
},
"headerName": {
"type": "string",
"example": "Authorization",
"example": "apikey",
"default": "apikey"
},
"queryParamName": {
Expand Down Expand Up @@ -608,7 +613,7 @@
}
}
},
"required":[
"required": [
"target",
"verb"
],
Expand Down

0 comments on commit 7842cf5

Please sign in to comment.