Skip to main content

Kong 网关 HMAC 鉴权 Python SDK

介绍

Kong 网关的的 Python 客户端 SDK,同样适用于移植到APISIX的HMAC鉴权,相关介绍:https://zhang.ge/5159.html

快速上手

SDK 安装

pip install kong-hmac

网关鉴权

import requests
from kong_hmac import HmacAuth

if __name__ == "__main__":
    # 根据实际情况修改
    USERNAME = "demo"
    SECRET = "ujHURnS5Wlb***********QmJdkDMEep"
    API_URL = "http://xxx.xxx.com/hmac_test"
    param = {"xxx": {"xxxx": "xxx"}}

    # 方式一:在初始化class的时候设置账号密钥
    hmac_auth = HmacAuth(hmac_user=USERNAME, hmac_secret=SECRET)
    headers = hmac_auth.get_auth_headers()

    # 方式二:在生成头部的时候设置账号密钥
    # hmac_auth = HmacAuth()
    # headers = hmac_auth.get_auth_headers(hmac_user=USERNAME, hmac_secret=SECRET)

    resp = requests.post(url=API_URL, json=param, headers=headers)

    if resp.status_code in [200, 201]:
        print(headers)
        exit("Test OK!")

    else:
        print(headers)
        print(resp.text)
        exit("Test Failed!")

Metadata

Release files for kong-hmac 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kong-hmac 1.0.0
File Size Uploaded
kong-hmac-1.0.0.tar.gz 3.7 kB Details

Release files / kong-hmac-1.0.0.tar.gz

Download URL kong-hmac-1.0.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3b70a839a1e5c4795bab2bb41dc2b26eeb91eec76a3affc83c9225e819c2b2ee
BLAKE2b-256 checksum
How to use checksums
f61da47a9399ffde444f0d7e5822e56c890e48430d1a8403806630fb84fc479c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.54.1 importlib-metadata/3.7.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page