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

Update API Key implementation #2323

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
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
Loading