Hi, there are a few syntax errors on the Python code, also, for specifying custom authentication checks, you must use the auth_check
option -just like the Python sample we have online-.
I did a few modifications on the code you’ve provided, you may check the code here:
Also if you’re interested in Go/gRPC plugins (which could perform much better), I’ve just pushed this sample (hooks.go
is the most interesting file here, will extend the README soon):
It should be possible to use this sample by doing go get
with the repository URL and building the program. Note that this is the gRPC approach, so your tyk.conf
should have this:
"coprocess_options": {
"enable_coprocess": true,
"coprocess_grpc_server": "tcp://127.0.0.1:5000"
},
You will also need to update your Docker settings to run a standard Tyk build (TYKVERSION
isn’t needed).
The coprocess_grpc_server
points to the Go server. When a request comes, Tyk will send it to this server and reply with a modified request/response object.
The last step is to use to enable rich plugins authentication for this API, a working API definition looks like this:
{
"name": "Tyk Test API",
"api_id": "1",
"org_id": "default",
"definition": {
"location": "",
"key": ""
},
"use_keyless": false,
"auth": {
"auth_header_name": ""
},
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"expires": "3000-01-02 15:04",
"use_extended_paths": true,
"extended_paths": {
"ignored": [],
"white_list": [],
"black_list": []
}
}
}
},
"proxy": {
"listen_path": "/quickstart/",
"target_url": "http://httpbin.org/",
"strip_listen_path": true
},
"custom_middleware_bundle": "test-bundle.zip",
"enable_coprocess_auth": true,
"do_not_track": true
}
The most important settings in this spec are:
-
use_keyless
: when true
, indicates that this is a protected API, access will be denied unless a valid session is provided (by Tyk or your rich plugins).
-
custom_middleware_bundle
: is the bundle filename, this will be fetched from your server, using the bundle_base_url
specified in your tyk.conf
.
-
enable_coprocess_auth
: indicates Tyk that you will authorize access access to this API by using rich plugins and not the standard Tyk tokens.
Best.