Skip to content

Commit

Permalink
change JWT->Oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
tharindu1st committed Sep 6, 2023
1 parent 4eb2647 commit a9269af
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 81 deletions.
8 changes: 4 additions & 4 deletions adapter/internal/oasparser/model/http_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ func concatAuthSchemes(schemeUp *dpv1alpha1.Authentication, schemeDown *dpv1alph
// tip: use concatScheme method
func getSecurity(authScheme *dpv1alpha1.Authentication) *Authentication {
authHeader := constants.AuthorizationHeader
if authScheme != nil && authScheme.Spec.Override.AuthTypes != nil && len(authScheme.Spec.Override.AuthTypes.JWT.Header) > 0 {
authHeader = authScheme.Spec.Override.AuthTypes.JWT.Header
if authScheme != nil && authScheme.Spec.Override.AuthTypes != nil && len(authScheme.Spec.Override.AuthTypes.Oauth2.Header) > 0 {
authHeader = authScheme.Spec.Override.AuthTypes.Oauth2.Header
}
sendTokenToUpstream := false
if authScheme != nil && authScheme.Spec.Override.AuthTypes != nil {
sendTokenToUpstream = authScheme.Spec.Override.AuthTypes.JWT.SendTokenToUpstream
sendTokenToUpstream = authScheme.Spec.Override.AuthTypes.Oauth2.SendTokenToUpstream
}
auth := &Authentication{Disabled: false,
TestConsoleKey: &TestConsoleKey{Header: constants.TestConsoleKeyHeader},
Expand All @@ -581,7 +581,7 @@ func getSecurity(authScheme *dpv1alpha1.Authentication) *Authentication {
return &Authentication{Disabled: true}
}
authFound := false
if authScheme.Spec.Override.AuthTypes != nil && authScheme.Spec.Override.AuthTypes.JWT.Disabled {
if authScheme.Spec.Override.AuthTypes != nil && authScheme.Spec.Override.AuthTypes.Oauth2.Disabled {
auth = &Authentication{Disabled: false,
TestConsoleKey: &TestConsoleKey{Header: constants.TestConsoleKeyHeader},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ type AuthSpec struct {

// APIAuth Authentication scheme type and details
type APIAuth struct {
// JWT is to specify the JWT authentication scheme details
// Oauth2 is to specify the Oauth2 authentication scheme details
//
// +optional
JWT JWTAuth `json:"jwt,omitempty"`
Oauth2 Oauth2Auth `json:"oauth2,omitempty"`

// APIKey is to specify the APIKey authentication scheme details
//
Expand Down Expand Up @@ -74,8 +74,8 @@ type TestConsoleKeyAuth struct {
SendTokenToUpstream bool `json:"sendTokenToUpstream,omitempty"`
}

// JWTAuth JWT Authentication scheme details
type JWTAuth struct {
// Oauth2Auth Oauth Authentication scheme details
type Oauth2Auth struct {

// Disabled is to disable JWT authentication
//
Expand Down
32 changes: 16 additions & 16 deletions adapter/internal/operator/apis/dp/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ spec:
type: object
nullable: true
type: array
jwt:
description: JWT is to specify the JWT authentication scheme
details
oauth2:
description: Oauth2 is to specify the Oauth2 authentication
scheme details
properties:
disabled:
default: false
Expand Down Expand Up @@ -139,9 +139,9 @@ spec:
type: object
nullable: true
type: array
jwt:
description: JWT is to specify the JWT authentication scheme
details
oauth2:
description: Oauth2 is to specify the Oauth2 authentication
scheme details
properties:
disabled:
default: false
Expand Down
29 changes: 7 additions & 22 deletions helm-charts/crds/dp.wso2.com_authentications.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# --------------------------------------------------------------------
# Copyright (c) 2023, WSO2 LLC. (http://wso2.com) All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -83,9 +68,9 @@ spec:
type: object
nullable: true
type: array
jwt:
description: JWT is to specify the JWT authentication scheme
details
oauth2:
description: Oauth2 is to specify the Oauth2 authentication
scheme details
properties:
disabled:
default: false
Expand Down Expand Up @@ -154,9 +139,9 @@ spec:
type: object
nullable: true
type: array
jwt:
description: JWT is to specify the JWT authentication scheme
details
oauth2:
description: Oauth2 is to specify the Oauth2 authentication
scheme details
properties:
disabled:
default: false
Expand Down
6 changes: 3 additions & 3 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ public class APIClient {
map<model:Authentication> authenticationMap = {};
model:AuthenticationExtenstionType authTypes = {};
foreach AuthenticationRequest authentication in authentications {
if authentication.authType == "JWT" {
JWTAuthentication jwtAuthentication = check authentication.cloneWithType(JWTAuthentication);
authTypes.jwt = {header: <string>jwtAuthentication.headerName, sendTokenToUpstream: <boolean>jwtAuthentication.sendTokenToUpstream, disabled: !jwtAuthentication.enabled};
if authentication.authType == "OAuth2" {
OAuth2Authentication oauth2Authentication = check authentication.cloneWithType(OAuth2Authentication);
authTypes.oauth2 = {header: <string>oauth2Authentication.headerName, sendTokenToUpstream: <boolean>oauth2Authentication.sendTokenToUpstream, disabled: !oauth2Authentication.enabled};
} else if authentication.authType == "APIKey" && authentication is APIKeyAuthentication {
APIKeyAuthentication apiKeyAuthentication = check authentication.cloneWithType(APIKeyAuthentication);
authTypes.apiKey = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public type AuthenticationData record {
};

public type AuthenticationExtenstionType record {
JWTAuthentication jwt?;
OAuth2Authentication oauth2?;
APIKey[] apiKey = [];
};

public type JWTAuthentication record {
public type OAuth2Authentication record {
string header?;
boolean sendTokenToUpstream?;
boolean disabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ components:
additionalProperties: false
AuthenticationRequest:
oneOf:
- $ref: "#/components/schemas/JWTAuthentication"
- $ref: "#/components/schemas/OAuth2Authentication"
- $ref: "#/components/schemas/APIKeyAuthentication"
discriminator:
propertyName: authType
mapping:
JWT: "#/components/schemas/JWTAuthentication"
OAuth2: "#/components/schemas/OAuth2Authentication"
APIKey: "#/components/schemas/APIKeyAuthentication"
Authentication:
type: object
Expand All @@ -93,7 +93,7 @@ components:
type: boolean
example: true
additionalProperties: false
JWTAuthentication:
OAuth2Authentication:
allOf:
- $ref: '#/components/schemas/Authentication'
- type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public function testJWTAuthenticationOnlyEnable() returns error? {
model:AuthenticationData expectedAuthenticationData = {
disabled: false,
authTypes: {
jwt: {
oauth2: {
disabled: false,
header: "Authorization",
sendTokenToUpstream: false
Expand Down Expand Up @@ -538,7 +538,7 @@ public function testAPIKeyAndJWTEnable() returns error? {
sendTokenToUpstream: false
}
],
jwt: {
oauth2: {
disabled: false,
header: "Authorization",
sendTokenToUpstream: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"properties": {
"authType": {
"type": "string",
"example": "JWT",
"description": "The type of authentication to be used, e.g., JWT, OAuth, etc."
"example": "OAuth2",
"description": "The type of authentication to be used, e.g., OAuth2, etc."
},
"sendTokenToUpstream": {
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ operations:
authTypeEnabled: true
scopes: []
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ operations:
authTypeEnabled: true
scopes: []
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ operations:
authTypeEnabled: true
scopes: []
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ operations:
authTypeEnabled: true
scopes: []
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ operations:
authTypeEnabled: true
scopes: []
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ operations:
- target: /get
verb: POST
authentication:
- authType: "JWT"
- authType: "OAuth2"
enabled: true
corsConfiguration:
corsConfigurationEnabled: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ operations:
- target: /get
verb: POST
authentication:
- authType: "JWT"
- authType: "OAuth2"
enabled: true
- authType: "APIKey"
enabled: true
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 @@ -112,14 +112,14 @@ public type CircuitBreaker record {
int maxRetries?;
};

public type AuthenticationRequest JWTAuthentication|APIKeyAuthentication;
public type AuthenticationRequest OAuth2Authentication|APIKeyAuthentication;

public type EndpointConfigurations record {
EndpointConfiguration production?;
EndpointConfiguration sandbox?;
};

public type JWTAuthentication record {|
public type OAuth2Authentication record {|
*Authentication;
boolean sendTokenToUpstream = false;
string headerName = "Authorization";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"properties": {
"authType": {
"type": "string",
"example": "JWT",
"description": "The type of authentication to be used, e.g., JWT, OAuth, etc."
"example": "OAuth2",
"description": "The type of authentication to be used, e.g., OAuth2, etc."
},
"sendTokenToUpstream": {
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime-ui/schema/apk-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ schemas:
properties:
authType:
type: string
example: JWT
description: The type of authentication to be used, e.g., JWT, OAuth, etc.
example: OAuth2
description: The type of authentication to be used, e.g., OAuth2, etc.
sendTokenToUpstream:
type: boolean
default: false
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime-ui/schema/apk-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"properties": {
"authType": {
"type": "string",
"example": "JWT",
"description": "The type of authentication to be used, e.g., JWT, OAuth, etc."
"example": "OAuth2",
"description": "The type of authentication to be used, e.g., OAuth2, etc."
},
"sendTokenToUpstream": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime-ui/templates/petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ apiRateLimit:
requestsPerUnit: 1000
unit: "Hour"
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime-ui/templates/pizza-shack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ apiRateLimit:
requestsPerUnit: 1000
unit: "Hour"
authentication:
- authType: "JWT"
- authType: "OAuth2"
sendTokenToUpstream: false
enabled: true
headerName: "Authorization"
Expand Down

0 comments on commit a9269af

Please sign in to comment.