Built to be run natively as a package by Tyk Gateways.
This is coded is intended to run as the "custom auth" part of the request lifecycle.
This will authenticate requests by connecting to DynamoDB and checking the Basic Auth credentials in the request to see if they match what's in the DB. If success, will let the request continue, otherwise will return an auth error.
In here,
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-2"),
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", ""),
})
Replace AKID and SECRET with your AWS credentials. Leave the third parameter exactly as is, an empty string. Make sure the region is accurate also.
In the root of the "main.go" file, run
go build -o ./middleware/go/main.so -buildmode=plugin ./middleware/go
Put the generated file somewhere Tyk Gateway can access it
go build -tags 'goplugin' -o tyk .
Then run the compiled Tyk
in API Designer, click on "Raw API Definition"
- Set
"driver": "goplugin"
and"use_go_plugin_auth": true
- Set the request lifecycle to be run
"custom_middleware": {
"auth_check": [
{
"name": "DynamoDBAuth",
"path": "./middleware/go/main.so"
}
],
"name" has to be the name of the GO function
"path" is wherever you put the binary generated in step 1
- Create an entry in DynamoDB
username - hash
-------------
foo - bar
- Base encode our user:password combo into "user:pwd" convention
foo:bar
becomes Zm9vOmJhcg==
-
Make cURL to Tyk Gateway.
curl http://www.tyk-test.com:8080/custom-auth-goplugin/headers -H "Authorization:Zm9vOmJhcg=="
-
Watch it rate limit!