Demo Tyk go plugin for custom auth and post auth hooks. Note the usage of Tyk packages.
docker run --rm -v pwd
:/go/src/plugin-build tykio/tyk-plugin-compiler:v2.9.3 my-plugin-293.so
docker run --rm -v pwd
:/plugin-source tykio/tyk-plugin-compiler:2.9.4.1 my-go-plugin-2941.so
get_time=yes
-current_time
is added as a header to your request and Tyk continues to reverse proxy the request to the backend.
curl -s http://www.tyk-test.com:8080/go-plugin-demo/get?get_time=yes
get_time != yes
- you get thecurrent_time
returned to you as the payload of the response. It's called "response ovverride". Tyk will stop the middleware execution chane and return response to the caller.
curl -s http://www.tyk-test.com:8080/go-plugin-demo/get?get_time=no
- Pass auth - authorization bearer is
abc
.
curl -s 'http://www.localhost:8080/go-plugin-demo/get?get_time=yes' --header 'Authorization: abc' |jq .
- Fail auth - authorization bearer is not
abc
.
curl -s 'http://www.localhost:8080/go-plugin-demo/get?get_time=yes' --header 'Authorization: def' |jq .