Are "config_data" available to JSVM auth plugins?

I have a auth check JSVM middleware JS file that is being invoked for an API

I next edited my API def JSON to include the following

"config_data": {
    "foo": "bar"
},

I then edited my middleware function w/ the following signature and logs statement:

myAuth.NewProcessRequest(function(request, session, config) {
    log("----> Running myAuth JSVM Auth Middleware");
    log("config= " + JSON.stringify(config));
    ....

When invoked I see this in the logs (config is null)

2017-07-20T17:22:17.360893893Z time="Jul 20 17:22:17" level=info msg="----> Running myAuth JSVM Auth Middleware" type=log-msg
2017-07-20T17:22:17.360946230Z time="Jul 20 17:22:17" level=info msg="config= undefined" type=log-msg

It should, so maybe you hit a bug. Investigating.

Leonid, Tyk Team

Also, can you confirm that you can see config_data object in “pre”/“post” middlewares?

Ok, something is a miss. I exported the API config, deleted it, then re-imported the JSON (below) via the dashboard.

The GUI reports this error

API object validation failed._

config_data: Additional property config_data is not allowed_

{
    "id": "5970e29be4b3480001d6a0e1",
    "name": "MY Auth",
    "slug": "my/auth/10",
    "api_id": "0b74be4969ec427949b0e332b6e02ca6",
    "org_id": "596cc1d5e4b3480001d6a0d9",
    "use_keyless": false,
    "use_oauth2": false,
    "use_openid": false,
    "config_data": {
      "foo": "bar"
    },
    "openid_options": {
        "providers": [],
        "segregate_by_client": false
    },
    "oauth_meta": {
        "allowed_access_types": [],
        "allowed_authorize_types": [],
        "auth_login_redirect": ""
    },
    "auth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": ""
    },
    "use_basic_auth": false,
    "enable_jwt": false,
    "use_standard_auth": false,
    "enable_coprocess_auth": true,
    "jwt_signing_method": "",
    "jwt_source": "",
    "jwt_identity_base_field": "",
    "jwt_client_base_field": "",
    "jwt_policy_field_name": "",
    "notifications": {
        "shared_secret": "",
        "oauth_on_keychange_url": ""
    },
    "enable_signature_checking": false,
    "hmac_allowed_clock_skew": -1,
    "base_identity_provided_by": "",
    "definition": {
        "location": "header",
        "key": "x-api-version"
    },
    "version_data": {
        "not_versioned": true,
        "versions": {
            "Default": {
                "name": "Default",
                "expires": "",
                "paths": {
                    "ignored": [],
                    "white_list": [],
                    "black_list": []
                },
                "use_extended_paths": true,
                "extended_paths": {},
                "global_headers": {},
                "global_headers_remove": [],
                "global_size_limit": 0,
                "override_target": ""
            }
        }
    },
    "uptime_tests": {
        "check_list": [],
        "config": {
            "expire_utime_after": 0,
            "service_discovery": {
                "use_discovery_service": false,
                "query_endpoint": "",
                "use_nested_query": false,
                "parent_data_path": "",
                "data_path": "",
                "port_data_path": "",
                "target_path": "",
                "use_target_list": false,
                "cache_timeout": 60,
                "endpoint_returns_list": false
            },
            "recheck_wait": 0
        }
    },
    "proxy": {
        "preserve_host_header": false,
        "listen_path": "/my/auth/10",
        "target_url": "http://192.168.3.249:9080/service/xxxx",
        "strip_listen_path": true,
        "enable_load_balancing": false,
        "target_list": [],
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": false,
            "query_endpoint": "",
            "use_nested_query": false,
            "parent_data_path": "",
            "data_path": "hostname",
            "port_data_path": "port",
            "target_path": "/api-slug",
            "use_target_list": false,
            "cache_timeout": 60,
            "endpoint_returns_list": false
        }
    },
    "disable_rate_limit": false,
    "disable_quota": false,
    "custom_middleware": {
        "pre": [],
        "post": [],
        "post_key_auth": [],
        "auth_check": {
            "name": "myAuth",
            "path": "middleware/myAuth.js",
            "require_session": false
        },
        "response": [],
        "driver": "",
        "id_extractor": {
            "extract_from": "header",
            "extract_with": "value",
            "extractor_config": {
                "header_name": "Authorization"
            }
        }
    },
    "custom_middleware_bundle": "",
    "cache_options": {
        "cache_timeout": 60,
        "enable_cache": true,
        "cache_all_safe_requests": false,
        "cache_response_codes": [],
        "enable_upstream_cache_control": false
    },
    "session_lifetime": 60,
    "active": true,
    "auth_provider": {
        "name": "",
        "storage_engine": "",
        "meta": {}
    },
    "session_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "event_handlers": {
        "events": {}
    },
    "enable_batch_request_support": false,
    "enable_ip_whitelisting": false,
    "allowed_ips": [],
    "dont_set_quota_on_create": false,
    "expire_analytics_after": 0,
    "response_processors": [],
    "CORS": {
        "enable": false,
        "allowed_origins": [],
        "allowed_methods": [],
        "allowed_headers": [],
        "exposed_headers": [],
        "allow_credentials": false,
        "max_age": 24,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "do_not_track": false,
    "tags": [],
    "enable_context_vars": false
}

Where did you add the config_data section? It needs to be in the root of the document.

see above, the config I pasted above is what I uploaded

You may need to update the schema in the tyk-dashboard/schemas folder to include the config data object, maybe it wasn’t uodated correctly when installed?

This is the latest version of the schema:

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "http://jsonschema.net",
    "additionalProperties": false,
    "properties": {
        "hook_references": {
            "type": "array"
        },
        "sort_by": {
            "type": "number"
        },
        "is_site": {
            "type": "boolean"
        },
        "api_model": {
            "type": "object"
        },
        "api_definition": {
            "additionalProperties": false,
            "type": "object",
            "properties": {
                "is_site": {
                    "type": "boolean"
                },
                "uptime_tests": {
                    "type": "object"
                },
                "expire_analytics_after": {
                    "type": "number"
                },
                "id": {
                    "type": "string"
                },
                "org_id": {
                    "type": "string"
                },
                "api_id": {
                    "type": "string"
                },
                "enable_ip_whitelisting": {
                    "type": "boolean"
                },
                "enable_context_vars": {
                    "type": "boolean"
                },
                "do_not_track": {
                    "type": "boolean"
                },
                "enable_jwt": {
                    "type": "boolean"
                },
                "use_openid": {
                    "type": "boolean"
                },
                "openid_options": {
                    "type": "object"
                },
                "use_standard_auth":{
                    "type": "boolean"
                },
                "enable_coprocess_auth": {
                    "type": "boolean"  
                },
                "base_identity_provided_by": {
                    "type": "string"
                },  
                "disable_rate_limit": {
                    "type": "boolean"
                },
                "disable_quota": {
                    "type": "boolean"
                },
                "custom_middleware_bundle": {
                    "type": "string"
                },
                "jwt_policy_field_name": {
                    "type": "string"
                },
                "jwt_signing_method": {
                    "type": "string"
                },
                "jwt_source": {
                    "type": "string"
                },
                "jwt_identity_base_field": {
                    "type": "string"
                },
                "jwt_client_base_field": {
                    "type": "string"
                },
                "use_keyless": {
                    "type": "boolean"
                },
                "use_basic_auth": {
                    "type": "boolean"
                },
                "allowed_ips": {
                    "type": "array"
                },
                "enable_batch_request_support": {
                    "type": "boolean"
                },
                "event_handlers": {
                    "type":"object"
                },
                "notifications": {
                    "type":"object"
                },
                "use_oauth2": {
                    "type": "boolean"
                },
                "oauth_meta": {
                    "type":"object"
                },
                "cache_options": {
                    "type":"object"
                },
                "tags": {
                    "type":"array"
                },
                "CORS": {
                    "type":"object"
                },
                "response_processors": {
                    "type":"array"
                },
                "auth_provider": {
                    "type":"object",
                    "properties": {
                        "name": {
                            "type": "string",
                            "enum": [""]
                        },
                        "storage_engine": {
                            "type": "string",
                            "enum": [""]
                        }
                    }
                },
                "session_provider": {
                    "type":"object",
                    "properties": {
                        "name": {
                            "type": "string",
                            "enum": [""]
                        },
                        "storage_engine": {
                            "type": "string",
                            "enum": [""]
                        }
                    }
                },
                "hmac_allowed_clock_skew": {
                    "type": "number"
                },
                "dont_set_quota_on_create": {
                    "type": "boolean"
                    },
                "custom_middleware": {
                    "type":"object",
                    "properties": {
                        "pre": {
                            "type": "array"
                        },
                        "post": {
                            "type": "array"
                        }
                    }
                },
                "session_lifetime": {
                    "type": "number"
                },
                "enable_signature_checking": {
                    "type": "boolean"
                },
                "active": {
                    "type": "boolean",
                    "id": "http://jsonschema.net/active"
                },
                "auth": {
                    "type": "object",
                    "id": "http://jsonschema.net/auth",
                    "properties": {
                        "auth_header_name": {
                            "type": "string",
                            "id": "http://jsonschema.net/auth/auth_header_name"
                        }
                    },
                    "required": [
                        "auth_header_name"
                    ]
                },
                "definition": {
                    "type": "object",
                    "id": "http://jsonschema.net/definition",
                    "properties": {
                        "key": {
                            "type": "string",
                            "id": "http://jsonschema.net/definition/key"
                        },
                        "location": {
                            "type": "string",
                            "id": "http://jsonschema.net/definition/location"
                        }
                    },
                    "required": [
                        "key",
                        "location"
                    ]
                },
                "name": {
                    "type": "string",
                    "id": "http://jsonschema.net/name"
                },
                "slug": {
                    "type": "string",
                    "pattern": "[a-zA-Z0-9]",
                    "id": "http://jsonschema.net/name"
                },
                "domain": {
                    "type": "string"
                },
                "check_host_against_uptime_tests": {
                            "type": "boolean"
                },
                "proxy": {
                    "type": "object",
                    "id": "http://jsonschema.net/proxy",
                    "properties": {
                        "target_url": {
                            "type": "string",
                            "id": "http://jsonschema.net/proxy/target_url"
                        },
                        "check_host_against_uptime_tests": {
                            "type": "boolean"
                        }
                    },
                    "required": [
                        "target_url"
                    ]
                },
                "hook_references": {
                    "type": "object"
                },
                "version_data": {
                    "type": "object",
                    "id": "http://jsonschema.net/version_data",
                    "properties": {
                        "not_versioned": {
                            "type": "boolean",
                            "id": "http://jsonschema.net/version_data/not_versioned"
                        },
                        "versions": {
                            "type": "object",
                            "id": "http://jsonschema.net/version_data/versions",
                            "patternProperties": {
                                "^[a-zA-Z0-9]+$": {
                                    "title": "versionInfoProperty",
                                    "type": "object",
                                    "id": "http://jsonschema.net/access_rights/versionInfoProperty",
                                    "properties": {
                                        "expires": {
                                            "type": "string",
                                            "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/expires"
                                        },
                                        "name": {
                                            "type": "string",
                                            "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/name"
                                        },
                                        "paths": {
                                            "type": "object",
                                            "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/paths",
                                            "properties": {
                                                "black_list": {
                                                    "type": "array",
                                                    "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/paths/black_list"
                                                },
                                                "ignored": {
                                                    "type": "array",
                                                    "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/paths/ignored"
                                                },
                                                "white_list": {
                                                    "type": "array",
                                                    "id": "http://jsonschema.net/version_data/versions/versionInfoProperty/paths/white_list"
                                                }
                                            }
                                        }
                                    },
                                    "required": [
                                        "name"
                                    ]
                                }
                            }
                        }
                    },
                    "required": [
                        "not_versioned",
                        "versions"
                    ]
                },
                "config_data": {
                    "type": "object"
                }
            },
            "required": [
                    "auth",
                    "name",
                    "proxy",
                    "version_data"
                ]
        }
    }
}

Well I just used the Tyk docker quickstart, so does that have a bug? missing schema?

The contents of mine say draft-03… so why not the same, (it is missing config_data tho)

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "http://jsonschema.net",
    "additionalProperties": false,

Ok this is driving me nuts.

a) I modified the schema for api_definitions on the dashboard container and restarted

b) re-imported the API def above (w/ config_data), it was accepted OK

c) re-ran a request against the API w/ the middleware above, log shows config as “undefined”

d) EXPORTED the api def again from the dashboard, the config_data section (that was present on import) is missing from the config in the exported JSON

Are you running the latest container of dashboard?

Yes latest as of the start of this week

i.e. this: //tyk.io/docs/tyk-on-premises/docker/

What version does it say in the top of your dashboard?

says tyk dashboard version 1.3.6

Right, that version doesn’t have config_data :slight_smile:

run:

docker pull tykio/tyk-dashboard:latest
docker pull tykio/tyk-gateway:latest
```

Then re-up the quickstart.

ha, new release 3 days ago, pulling now and will report back

Fixed in 1.3.7

2017-07-20T20:47:34.036122135Z time="Jul 20 20:47:34" level=info msg="config= {\"config_data\":{\"foo\":\"bar\"}}" type=log-msg

1 Like

so my related to all these posts is this remaining one NPM and JSVM, custom basic-auth plugin more details? - #18 by bitsofinfo