Skip to content

TykTechnologies/native-go-auth-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-dynamodb-basicauth-plugin

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.

Setup AWS session in the GO Plugin

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.

Build the plugin binary (shared object) without using go

docker run --rm -v pwd:/go/src/plugin-build tykio/tyk-plugin-compiler:v2.9.3 main.so

Build the plugin binary (shared object) using go

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

Build Tyk binary to run GOPLUGINS

Note: this is not required any longer, since Tyk published binaries support it already.

go build -tags 'goplugin' -o tyk .

Then run the compiled Tyk

Setup your API

in API Designer, click on "Raw API Definition"

  1. Set "driver": "goplugin" and "use_go_plugin_auth": true
  2. 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

Testing

  1. Create an entry in DynamoDB
username - hash
-------------
foo - bar
  1. Base encode our user:password combo into "user:pwd" convention

foo:bar becomes Zm9vOmJhcg==

  1. Make cURL to Tyk Gateway. curl http://www.tyk-test.com:8080/custom-auth-goplugin/headers -H "Authorization:Zm9vOmJhcg=="

  2. Watch it rate limit!

About

Built to be run natively as a package by Tyk Gateway, will check basic auth credentials against AWS' DynamoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages