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

[TT-13185] fix missing extracts #6685

Merged
merged 7 commits into from
Oct 30, 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
4 changes: 1 addition & 3 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ type UpstreamOAuth struct {
// ClientCredentials holds the client credentials for upstream OAuth2 authentication.
ClientCredentials ClientCredentials `bson:"client_credentials" json:"client_credentials"`
// PasswordAuthentication holds the configuration for upstream OAauth password authentication flow.
PasswordAuthentication PasswordAuthentication `bson:"password_authentication,omitempty" json:"passwordAuthentication,omitempty"`
PasswordAuthentication PasswordAuthentication `bson:"password,omitempty" json:"password,omitempty"`
}

// PasswordAuthentication holds the configuration for upstream OAuth2 password authentication flow.
Expand Down Expand Up @@ -853,8 +853,6 @@ type ClientCredentials struct {
ClientAuthData
// Header holds the configuration for the custom header to be used for OAuth authentication.
Header AuthSource `bson:"header" json:"header"`
// Enabled activates upstream OAuth2 client credentials authentication.
Enabled bool `bson:"enabled" json:"enabled"`
// TokenURL is the resource server's token endpoint
// URL. This is a constant specific to each server.
TokenURL string `bson:"token_url" json:"token_url"`
Expand Down
3 changes: 0 additions & 3 deletions apidef/oas/oas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ func TestOAS_ExtractTo_ResetAPIDefinition(t *testing.T) {
"APIDefinition.AnalyticsPlugin.Enabled",
"APIDefinition.AnalyticsPlugin.PluginPath",
"APIDefinition.AnalyticsPlugin.FuncName",
"APIDefinition.UpstreamAuth.OAuth.ClientCredentials.Enabled",
"APIDefinition.UpstreamAuth.OAuth.PasswordAuthentication.Header.Enabled",
"APIDefinition.UpstreamAuth.OAuth.PasswordAuthentication.Header.Name",
}

assert.Equal(t, expectedFields, noOASSupportFields)
Expand Down
6 changes: 3 additions & 3 deletions apidef/oas/schema/x-tyk-api-gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@
"header": {
"$ref": "#/definitions/X-Tyk-AuthSource"
},
"extra_metadata": {
"extraMetadata": {
"type": "array"
}
},
Expand All @@ -2083,7 +2083,7 @@
"tokenUrl"
]
},
"passwordAuthentication": {
"password": {
"type": "object",
"properties": {
"clientId": {
Expand All @@ -2110,7 +2110,7 @@
"header": {
"$ref": "#/definitions/X-Tyk-AuthSource"
},
"extra_metadata": {
"extraMetadata": {
"type": "array"
}
},
Expand Down
10 changes: 9 additions & 1 deletion apidef/oas/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ type UpstreamOAuth struct {
// ClientCredentials holds the configuration for OAuth2 Client Credentials flow.
ClientCredentials *ClientCredentials `bson:"clientCredentials,omitempty" json:"clientCredentials,omitempty"`
// PasswordAuthentication holds the configuration for upstream OAauth password authentication flow.
PasswordAuthentication *PasswordAuthentication `bson:"passwordAuthentication,omitempty" json:"passwordAuthentication,omitempty"`
PasswordAuthentication *PasswordAuthentication `bson:"password,omitempty" json:"password,omitempty"`
}

// PasswordAuthentication holds the configuration for upstream OAuth2 password authentication flow.
Expand Down Expand Up @@ -779,6 +779,14 @@ func (p *PasswordAuthentication) ExtractTo(api *apidef.PasswordAuthentication) {
api.TokenURL = p.TokenURL
api.Scopes = p.Scopes
api.ExtraMetadata = p.ExtraMetadata

if p.Header == nil {
p.Header = &AuthSource{}
defer func() {
p.Header = nil
}()
}
p.Header.ExtractTo(&api.Header.Enabled, &api.Header.Name)
}

func (u *UpstreamOAuth) ExtractTo(api *apidef.UpstreamOAuth) {
Expand Down
2 changes: 1 addition & 1 deletion apidef/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ const Schema = `{
"token_url"
]
},
"password_authentication": {
"password": {
"type": "object",
"properties": {
"client_id": {
Expand Down
1 change: 0 additions & 1 deletion gateway/mw_oauth2_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func TestUpstreamOauth2(t *testing.T) {
defer t.Cleanup(func() { ts.Close() })

cfg := apidef.ClientCredentials{
Enabled: true,
ClientAuthData: apidef.ClientAuthData{
ClientID: "CLIENT_ID",
ClientSecret: "CLIENT_SECRET",
Expand Down
Loading