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

[DRAFT] Revert "Add JWT authentication" #2089

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 6 additions & 7 deletions adapter/api/proto/wso2/discovery/api/api_authentication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ message APIKey {
message JWT {
string header = 1; // name of the header containing the JWT
bool sendTokenToUpstream = 2; // send the token to upstream
repeated string audience = 3;
}

message Oauth2 {
string header = 1; // name of the header containing the JWT
bool sendTokenToUpstream = 2; // send the token to upstream
}

message APIAuthentication {
bool disabled = 1; // disable authentication
JWT jwt = 2;
repeated APIKey apikey = 3;
Oauth2 Oauth2 = 4;
TestConsoleKey testConsoleKey = 4;
}

message TestConsoleKey {
string header = 1; // name of the header containing the test key
bool sendTokenToUpstream = 2; // send the token to upstream
}
16 changes: 11 additions & 5 deletions adapter/internal/oasparser/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func castAPIAuthenticationsToEnforcerAPIAuthentications(authentication *model.Au
enforcerAuthentication.Jwt = &api.JWT{
Header: strings.ToLower(authentication.JWT.Header),
SendTokenToUpstream: authentication.JWT.SendTokenToUpstream,
Audience: authentication.JWT.Audience,
}
}
var apiKeys []*api.APIKey
Expand All @@ -274,12 +273,19 @@ func castAPIAuthenticationsToEnforcerAPIAuthentications(authentication *model.Au
})
}
enforcerAuthentication.Apikey = apiKeys
if authentication.Oauth2 != nil {
enforcerAuthentication.Oauth2 = &api.Oauth2{
Header: strings.ToLower(authentication.Oauth2.Header),
SendTokenToUpstream: authentication.Oauth2.SendTokenToUpstream,
if authentication.TestConsoleKey != nil {
enforcerAuthentication.TestConsoleKey = &api.TestConsoleKey{
Header: strings.ToLower(authentication.TestConsoleKey.Header),
SendTokenToUpstream: authentication.TestConsoleKey.SendTokenToUpstream,
}
}
if authentication.TestConsoleKey != nil {
enforcerAuthentication.TestConsoleKey = &api.TestConsoleKey{
Header: strings.ToLower(authentication.TestConsoleKey.Header),
SendTokenToUpstream: authentication.TestConsoleKey.SendTokenToUpstream,
}
}

return enforcerAuthentication
}

Expand Down
7 changes: 3 additions & 4 deletions adapter/internal/oasparser/model/api_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ type Authentication struct {
Disabled bool
JWT *JWT
APIKey []APIKey
Oauth2 *Oauth2
TestConsoleKey *TestConsoleKey
}

// JWT holds JWT related configurations
type JWT struct {
Header string
SendTokenToUpstream bool
Audience []string
}

// Oauth2 holds Oauth2 related configurations
type Oauth2 struct {
// TestConsoleKey holds testkey related configurations
type TestConsoleKey struct {
Header string
SendTokenToUpstream bool
}
Expand Down
23 changes: 8 additions & 15 deletions adapter/internal/oasparser/model/http_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package model

import (
"github.com/google/uuid"
"github.com/wso2/apk/adapter/internal/loggers"
"github.com/wso2/apk/adapter/internal/oasparser/constants"
"github.com/wso2/apk/adapter/internal/operator/utils"
dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
Expand Down Expand Up @@ -233,28 +234,19 @@ func getSecurity(authScheme *dpv1alpha2.Authentication) *Authentication {
sendTokenToUpstream = authScheme.Spec.Override.AuthTypes.Oauth2.SendTokenToUpstream
}
auth := &Authentication{Disabled: false,
Oauth2: &Oauth2{Header: authHeader, SendTokenToUpstream: sendTokenToUpstream},
TestConsoleKey: &TestConsoleKey{Header: constants.TestConsoleKeyHeader},
JWT: &JWT{Header: authHeader, SendTokenToUpstream: sendTokenToUpstream},
}
if authScheme != nil && authScheme.Spec.Override != nil {
if authScheme.Spec.Override.Disabled != nil && *authScheme.Spec.Override.Disabled {
return &Authentication{Disabled: true}
}
authFound := false
if authScheme.Spec.Override.AuthTypes != nil && !authScheme.Spec.Override.AuthTypes.Oauth2.Disabled {
authFound = true
} else {
auth = &Authentication{Disabled: false}
}
if authScheme.Spec.Override.AuthTypes != nil && authScheme.Spec.Override.AuthTypes.JWT.Disabled != nil && !*authScheme.Spec.Override.AuthTypes.JWT.Disabled {
audience := make([]string, 0)
if len(authScheme.Spec.Override.AuthTypes.JWT.Audience) > 0 {
audience = authScheme.Spec.Override.AuthTypes.JWT.Audience
if authScheme.Spec.Override.AuthTypes != nil && authScheme.Spec.Override.AuthTypes.Oauth2.Disabled {
auth = &Authentication{Disabled: false,
TestConsoleKey: &TestConsoleKey{Header: constants.TestConsoleKeyHeader},
}
jwtHeader := constants.TestConsoleKeyHeader
if len(authScheme.Spec.Override.AuthTypes.JWT.Header) > 0 {
jwtHeader = authScheme.Spec.Override.AuthTypes.JWT.Header
}
auth.JWT = &JWT{Header: jwtHeader, SendTokenToUpstream: sendTokenToUpstream, Audience: audience}
} else {
authFound = true
}
if authScheme.Spec.Override.AuthTypes != nil && authScheme.Spec.Override.AuthTypes.APIKey != nil {
Expand All @@ -270,6 +262,7 @@ func getSecurity(authScheme *dpv1alpha2.Authentication) *Authentication {
auth.APIKey = apiKeys
}
if !authFound {
loggers.LoggerOasparser.Debug("Disabled security.")
return &Authentication{Disabled: true}
}
}
Expand Down
Loading
Loading