Categorygithub.com/tyktechnologies/custom-plugins
module
0.0.0-20241108211809-e417158c4f9d
Repository: https://github.com/tyktechnologies/custom-plugins.git
Documentation: pkg.go.dev

# README

Custom Gateway Plugins

This is a repository that contains examples of Tyk Plugins. A Plugin is a custom middleware that is injected into the API request lifecycle, which further complements the built-in Tyk functionality such as authentication & rate limiting.

Here's the different phases you can inject plugins in the request lifecycle. A response plugin is also possible.

Custom Go Plugin Examples

LanguagePhaseDescriptionLink
GolangPreInjects client certificate attributes as a HeaderLink
GoLangPost-AuthOAuth2 IntrospectionLink
GoLangPost-AuthAuthorizes request against OPALink
GolangPost + AuthDummy one to test the 2 hooks in goLink
GolangPostInjects Key Meta Data into a HeaderLink
GolangPreChecks Basic Auth creds against an AWS DynamoDB instanceLink
GolangPreCustom Cache on upstream failureLink
GolangPreRequest funneling until cache is builtLink
GolangPreUpstream URL rewrite based on header, query or body valueLink
GolangPostUpstream OAuth2.0 (Client credentials flow)Link
GolangPostInvoke AWS Lambda with IAM CredentialsLink
GolangPostSend Custom Error Message in Plugin w/ ConditionalsLink
GolangAnyEstablish a connection to Redis databaseLink
GolangAnalyticsManipulate Tyk analytics recordsLink

gRPC Plugin Languages

LanguagePhaseDescriptionLink
gRPC (GoLang)PreHeader Injection & Auth exampleLink
gRPC (GoLang)PreInvokes an AWS LambdaLink
gRPC (Node)Pre / AutgSimple NODE example with access to config data LambdaLink
gRPC (Java)AuthDecodes JWT, inserts a claim and resigns itLink
gRPC (Java)PostInserts Metadata from the portal requested key as an HTTP headerLink
gRPC (.NET)AuthPerforms auth check against a SQL serverLink
gRPC (Ruby)PreModifies HTTP headerLink
gRPC (Python)PreInserts a HTTP headerLink

Javascript Plugin Languages

LanguagePhaseDescriptionLink
JavascriptPreInserts tracing ID in headerLink
JavascriptPreAuth Token & mTLS protectionLink
JavascriptPreEvaluates the validity of a Tyk TokenLink
JavascriptPostChecks API requests against a WAFLink
JavascriptPost-AuthChecks the request path against the user's meta data. If there is a cross-over, will deny the requestLink

Lua Plugin Languages

LanguagePhaseDescriptionLink
LuaPreheader injectionLink

Python Plugin Languages

LanguagePhaseDescriptionLink
PythonAuthChecks API requests against a hard-coded tokenLink
PythonAuthValidates credentials against an LDAP serverLink
PythonPreThis plugin sends a message to a queue server, it uses kombu as the messaging libraryLink
PythonPreThis plugin sends log data to a Datadog agent.Link
PythonPreThis plugin sends log data to a Loggly HTTPS endpointLink
PythonPreThis plugin will block requests from specific user agents, using regular expressions.Link
PythonPre + PostInserts a correlation ID as a headerLink
PythonPostInjects a signed JWT as Authorization HeaderLink
PythonResponseModifies the header and body of a responseLink

Virtual Endpoints

Virtual Endpoints are slightly different, more of a FaaS / Lambda as opposed to a plugin, and thus are treated differently

LanguageDescriptionLink
JavascriptTyk as an OAuth2.0 Client in client_credentials flow in Auth0https://gist.github.com/letzya/ba7c2cd833c11fac61ae4a1d1908f1dc
JavascriptTyk as an OAuth2.0 Client in client_credentials flow in Azurehttps://gist.github.com/letzya/7e852181643e871481a7997ae3d5b84a
JavascriptDemo body transform of response, XML to JSON using petstore's endpoint /pet/{id}https://gist.github.com/letzya/7df4dbc37f2f075795995efb8e205d3e
JavascriptMake POST request with FormData to UpstreamLink
JavascriptCreate API Key via Dashboard APILink

Requests

Have a cool or useful idea to add to this list? Feel free to open an issue.

Developers

If adding an example, first off, thank you.

Create a new directory the following name pattern:

<language>-<phase>-<description1>_<description2>_<description3>

For example:

js-pre-insert_header/
|- README.md
|- myplugin.js
|- apidef.js
  1. Include a README with instructions, and the supporting files in the directory

# Packages

No description provided by the author