Skip to main content

Kong 网关HMAC鉴权SDK

Project description

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!")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kong-hmac-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file kong-hmac-1.0.0.tar.gz.

File metadata

  • Download URL: kong-hmac-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for kong-hmac-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3b70a839a1e5c4795bab2bb41dc2b26eeb91eec76a3affc83c9225e819c2b2ee
MD5 f920c20d1c3b681faddd0e1241fa0bd5
BLAKE2b-256 f61da47a9399ffde444f0d7e5822e56c890e48430d1a8403806630fb84fc479c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page