@@ -3183,6 +3183,7 @@ async function editGateway(gatewayId) {
3183
3183
const authHeadersSection = safeGetElement (
3184
3184
"auth-headers-fields-gw-edit" ,
3185
3185
) ;
3186
+ const authOAuthSection = safeGetElement ( "auth-oauth-fields-gw-edit" ) ;
3186
3187
3187
3188
// Individual fields
3188
3189
const authUsernameField = safeGetElement (
@@ -3203,6 +3204,16 @@ async function editGateway(gatewayId) {
3203
3204
"auth-headers-fields-gw-edit" ,
3204
3205
) ?. querySelector ( "input[name='auth_header_value']" ) ;
3205
3206
3207
+ // OAuth fields
3208
+ const oauthGrantTypeField = safeGetElement ( "oauth-grant-type-gw-edit" ) ;
3209
+ const oauthClientIdField = safeGetElement ( "oauth-client-id-gw-edit" ) ;
3210
+ const oauthClientSecretField = safeGetElement ( "oauth-client-secret-gw-edit" ) ;
3211
+ const oauthTokenUrlField = safeGetElement ( "oauth-token-url-gw-edit" ) ;
3212
+ const oauthAuthUrlField = safeGetElement ( "oauth-authorization-url-gw-edit" ) ;
3213
+ const oauthRedirectUriField = safeGetElement ( "oauth-redirect-uri-gw-edit" ) ;
3214
+ const oauthScopesField = safeGetElement ( "oauth-scopes-gw-edit" ) ;
3215
+ const oauthAuthCodeFields = safeGetElement ( "oauth-auth-code-fields-gw-edit" ) ;
3216
+
3206
3217
// Hide all auth sections first
3207
3218
if ( authBasicSection ) {
3208
3219
authBasicSection . style . display = "none" ;
@@ -3213,6 +3224,9 @@ async function editGateway(gatewayId) {
3213
3224
if ( authHeadersSection ) {
3214
3225
authHeadersSection . style . display = "none" ;
3215
3226
}
3227
+ if ( authOAuthSection ) {
3228
+ authOAuthSection . style . display = "none" ;
3229
+ }
3216
3230
3217
3231
switch ( gateway . authType ) {
3218
3232
case "basic" :
@@ -3245,6 +3259,41 @@ async function editGateway(gatewayId) {
3245
3259
}
3246
3260
}
3247
3261
break ;
3262
+ case "oauth" :
3263
+ if ( authOAuthSection ) {
3264
+ authOAuthSection . style . display = "block" ;
3265
+ }
3266
+ // Populate OAuth fields if available
3267
+ if ( gateway . oauthConfig ) {
3268
+ const config = gateway . oauthConfig ;
3269
+ if ( oauthGrantTypeField && config . grant_type ) {
3270
+ oauthGrantTypeField . value = config . grant_type ;
3271
+ // Show/hide authorization code fields based on grant type
3272
+ if ( oauthAuthCodeFields ) {
3273
+ oauthAuthCodeFields . style . display =
3274
+ config . grant_type === "authorization_code" ? "block" : "none" ;
3275
+ }
3276
+ }
3277
+ if ( oauthClientIdField && config . client_id ) {
3278
+ oauthClientIdField . value = config . client_id ;
3279
+ }
3280
+ if ( oauthClientSecretField ) {
3281
+ oauthClientSecretField . value = "" ; // Don't populate secret for security
3282
+ }
3283
+ if ( oauthTokenUrlField && config . token_url ) {
3284
+ oauthTokenUrlField . value = config . token_url ;
3285
+ }
3286
+ if ( oauthAuthUrlField && config . authorization_url ) {
3287
+ oauthAuthUrlField . value = config . authorization_url ;
3288
+ }
3289
+ if ( oauthRedirectUriField && config . redirect_uri ) {
3290
+ oauthRedirectUriField . value = config . redirect_uri ;
3291
+ }
3292
+ if ( oauthScopesField && config . scopes && Array . isArray ( config . scopes ) ) {
3293
+ oauthScopesField . value = config . scopes . join ( " " ) ;
3294
+ }
3295
+ }
3296
+ break ;
3248
3297
case "" :
3249
3298
default :
3250
3299
// No auth – keep everything hidden
@@ -3658,6 +3707,7 @@ function handleAuthTypeSelection(
3658
3707
basicFields ,
3659
3708
bearerFields ,
3660
3709
headersFields ,
3710
+ oauthFields ,
3661
3711
) {
3662
3712
if ( ! basicFields || ! bearerFields || ! headersFields ) {
3663
3713
console . warn ( "Auth field elements not found" ) ;
@@ -3666,30 +3716,40 @@ function handleAuthTypeSelection(
3666
3716
3667
3717
// Hide all fields first
3668
3718
[ basicFields , bearerFields , headersFields ] . forEach ( ( field ) => {
3669
- field . style . display = "none" ;
3719
+ if ( field ) field . style . display = "none" ;
3670
3720
} ) ;
3671
3721
3722
+ // Hide OAuth fields if they exist
3723
+ if ( oauthFields ) {
3724
+ oauthFields . style . display = "none" ;
3725
+ }
3726
+
3672
3727
// Show relevant field based on selection
3673
3728
switch ( value ) {
3674
3729
case "basic" :
3675
- basicFields . style . display = "block" ;
3730
+ if ( basicFields ) basicFields . style . display = "block" ;
3676
3731
break ;
3677
3732
case "bearer" :
3678
- bearerFields . style . display = "block" ;
3733
+ if ( bearerFields ) bearerFields . style . display = "block" ;
3679
3734
break ;
3680
3735
case "authheaders" : {
3681
- headersFields . style . display = "block" ;
3682
- // Ensure at least one header row is present
3683
- const containerId =
3684
- headersFields . querySelector ( '[id$="-container"]' ) ?. id ;
3685
- if ( containerId ) {
3686
- const container = document . getElementById ( containerId ) ;
3687
- if ( container && container . children . length === 0 ) {
3688
- addAuthHeader ( containerId ) ;
3736
+ if ( headersFields ) {
3737
+ headersFields . style . display = "block" ;
3738
+ // Ensure at least one header row is present
3739
+ const containerId =
3740
+ headersFields . querySelector ( '[id$="-container"]' ) ?. id ;
3741
+ if ( containerId ) {
3742
+ const container = document . getElementById ( containerId ) ;
3743
+ if ( container && container . children . length === 0 ) {
3744
+ addAuthHeader ( containerId ) ;
3745
+ }
3689
3746
}
3690
3747
}
3691
3748
break ;
3692
3749
}
3750
+ case "oauth" :
3751
+ if ( oauthFields ) oauthFields . style . display = "block" ;
3752
+ break ;
3693
3753
default :
3694
3754
// All fields already hidden
3695
3755
break ;
@@ -6080,6 +6140,42 @@ async function handleEditGatewayFormSubmit(e) {
6080
6140
JSON . stringify ( passthroughHeaders ) ,
6081
6141
) ;
6082
6142
6143
+ // Handle OAuth configuration
6144
+ const authType = formData . get ( "auth_type" ) ;
6145
+ if ( authType === "oauth" ) {
6146
+ const oauthConfig = {
6147
+ grant_type : formData . get ( "oauth_grant_type" ) ,
6148
+ client_id : formData . get ( "oauth_client_id" ) ,
6149
+ client_secret : formData . get ( "oauth_client_secret" ) ,
6150
+ token_url : formData . get ( "oauth_token_url" ) ,
6151
+ scopes : formData . get ( "oauth_scopes" )
6152
+ ? formData
6153
+ . get ( "oauth_scopes" )
6154
+ . split ( " " )
6155
+ . filter ( ( s ) => s . trim ( ) )
6156
+ : [ ] ,
6157
+ } ;
6158
+
6159
+ // Add authorization code specific fields
6160
+ if ( oauthConfig . grant_type === "authorization_code" ) {
6161
+ oauthConfig . authorization_url = formData . get (
6162
+ "oauth_authorization_url" ,
6163
+ ) ;
6164
+ oauthConfig . redirect_uri = formData . get ( "oauth_redirect_uri" ) ;
6165
+ }
6166
+
6167
+ // Remove individual OAuth fields and add as oauth_config
6168
+ formData . delete ( "oauth_grant_type" ) ;
6169
+ formData . delete ( "oauth_client_id" ) ;
6170
+ formData . delete ( "oauth_client_secret" ) ;
6171
+ formData . delete ( "oauth_token_url" ) ;
6172
+ formData . delete ( "oauth_scopes" ) ;
6173
+ formData . delete ( "oauth_authorization_url" ) ;
6174
+ formData . delete ( "oauth_redirect_uri" ) ;
6175
+
6176
+ formData . append ( "oauth_config" , JSON . stringify ( oauthConfig ) ) ;
6177
+ }
6178
+
6083
6179
const isInactiveCheckedBool = isInactiveChecked ( "gateways" ) ;
6084
6180
formData . append ( "is_inactive_checked" , isInactiveCheckedBool ) ;
6085
6181
// Submit via fetch
@@ -6697,6 +6793,7 @@ function setupAuthenticationToggles() {
6697
6793
basicId : "auth-basic-fields-gw-edit" ,
6698
6794
bearerId : "auth-bearer-fields-gw-edit" ,
6699
6795
headersId : "auth-headers-fields-gw-edit" ,
6796
+ oauthId : "auth-oauth-fields-gw-edit" ,
6700
6797
} ,
6701
6798
{
6702
6799
id : "edit-auth-type" ,
@@ -6765,6 +6862,15 @@ function setupFormHandlers() {
6765
6862
} ) ;
6766
6863
}
6767
6864
6865
+ // Add OAuth grant type change handler for Edit Gateway modal
6866
+ const editOAuthGrantTypeField = safeGetElement ( "oauth-grant-type-gw-edit" ) ;
6867
+ if ( editOAuthGrantTypeField ) {
6868
+ editOAuthGrantTypeField . addEventListener (
6869
+ "change" ,
6870
+ handleEditOAuthGrantTypeChange ,
6871
+ ) ;
6872
+ }
6873
+
6768
6874
const toolForm = safeGetElement ( "add-tool-form" ) ;
6769
6875
if ( toolForm ) {
6770
6876
toolForm . addEventListener ( "submit" , handleToolFormSubmit ) ;
@@ -6907,6 +7013,38 @@ function handleOAuthGrantTypeChange() {
6907
7013
}
6908
7014
}
6909
7015
7016
+ function handleEditOAuthGrantTypeChange ( ) {
7017
+ const grantType = this . value ;
7018
+ const authCodeFields = safeGetElement ( "oauth-auth-code-fields-gw-edit" ) ;
7019
+
7020
+ if ( authCodeFields ) {
7021
+ if ( grantType === "authorization_code" ) {
7022
+ authCodeFields . style . display = "block" ;
7023
+
7024
+ // Make authorization code specific fields required
7025
+ const requiredFields =
7026
+ authCodeFields . querySelectorAll ( 'input[type="url"]' ) ;
7027
+ requiredFields . forEach ( ( field ) => {
7028
+ field . required = true ;
7029
+ } ) ;
7030
+
7031
+ // Show additional validation for required fields
7032
+ console . log (
7033
+ "Authorization Code flow selected - additional fields are now required" ,
7034
+ ) ;
7035
+ } else {
7036
+ authCodeFields . style . display = "none" ;
7037
+
7038
+ // Remove required validation for hidden fields
7039
+ const requiredFields =
7040
+ authCodeFields . querySelectorAll ( 'input[type="url"]' ) ;
7041
+ requiredFields . forEach ( ( field ) => {
7042
+ field . required = false ;
7043
+ } ) ;
7044
+ }
7045
+ }
7046
+ }
7047
+
6910
7048
function setupSchemaModeHandlers ( ) {
6911
7049
const schemaModeRadios = document . getElementsByName ( "schema_input_mode" ) ;
6912
7050
const uiBuilderDiv = safeGetElement ( "ui-builder" ) ;
0 commit comments