Skip to content

Latest commit

 

History

History
51 lines (42 loc) · 1.49 KB

README.md

File metadata and controls

51 lines (42 loc) · 1.49 KB

Python module for HMAC Authentication with Kong

This is a python module for generating HTTP request headers for HMAC authentication with Kong. More specifically, Kong's HMAC Authentication Plugin.

This module was written for load testing with Locust and used in conjuction with Locust Docker.

Usage

GET request:

from kong_hmac import generate_request_headers
import requests

key_id = 'my-key-id'
secret = b'my-secret'
url = 'https://example.com/api/resource'
get_request_headers = generate_request_headers(key_id, secret, url)
r = requests.get(url, headers=get_request_headers)
print ('Response code: %d\n' % r.status_code)
print (r.text)

POST request:

from kong_hmac import generate_request_headers
import request

key_id = 'my-key-id'
secret = b'my-secret'
url = 'https://example.com/api/resource'
content_type = 'application/json'
payload = open('payload.json', 'r').read()
post_request_headers = generate_request_headers(key_id, secret, url, payload, content_type)
r = requests.post(url, headers=post_request_headers, data=payload)
print ('Response code: %d\n' % r.status_code)
print (r.text)

payload.json:

{
	"key1": "value1",
	"key2": "value2"
}

Reference

HTTP Signatures Specification

License

MIT License - see the LICENSE file for details