Skip to content

Commit

Permalink
Add default values for API Key Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Apr 30, 2024
1 parent 3e7c0cd commit c7ca062
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
8 changes: 3 additions & 5 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,14 @@ public class APIClient {
} else if authentication.authType == "JWT" {
JWTAuthentication jwtAuthentication = check authentication.cloneWithType(JWTAuthentication);
authTypes.jwt = {header: <string>jwtAuthentication.headerName, sendTokenToUpstream: <boolean>jwtAuthentication.sendTokenToUpstream, disabled: !jwtAuthentication.enabled, audience: jwtAuthentication.audience};
} else if authentication.authType == "APIKey" {
} else if authentication.authType == "APIKey" && authentication is APIKeyAuthentication {
APIKeyAuthentication apiKeyAuthentication = check authentication.cloneWithType(APIKeyAuthentication);
model:APIKey[] apiKeys = [];
boolean|() headerEnabled = apiKeyAuthentication.headerEnable;
boolean|() queryEnabled = apiKeyAuthentication.queryParamEnable;

if headerEnabled is boolean && headerEnabled {
if apiKeyAuthentication.headerEnable {
apiKeys.push({'in: "Header", name: <string>apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
if queryEnabled is boolean && queryEnabled {
if apiKeyAuthentication.queryParamEnable {
apiKeys.push({'in: "Query", name: <string>apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
authTypes.apiKey = apiKeys;
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 @@ -18,7 +18,6 @@ authentication:
- authType: "APIKey"
enabled: true
queryParamEnable: true
headerEnable: true
corsConfiguration:
corsConfigurationEnabled: false
accessControlAllowOrigins:
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ authentication:
- authType: "APIKey"
enabled: true
queryParamEnable: true
headerEnable: true
corsConfiguration:
corsConfigurationEnabled: false
accessControlAllowOrigins:
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 @@ -277,8 +277,8 @@ public type APIKeyAuthentication record {|
boolean sendTokenToUpstream = false;
string headerName = "apiKey";
string queryParamName = "apiKey";
boolean headerEnable?;
boolean queryParamEnable?;
boolean headerEnable = 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 c7ca062

Please sign in to comment.