Skip to main content

Python implementation of the AWS4 compatible Escher HTTP request signing protocol.

Project description

EscherPython - HTTP request signing lib Build Status

Escher helps you creating secure HTTP requests (for APIs) by signing HTTP(s) requests. It's both a server side and client side implementation. The status is work in progress.

The algorithm is based on Amazon's AWS Signature Version 4, but we have generalized and extended it.

More details are available at escherauth.io.

Signing a request

Escher works by calculating a cryptographic signature of your request, and adding it (and other authentication information) to said request.

Usually you will want to add the authentication information to the request by appending extra headers to it.

from escherauth import Escher

request = {
    'method': 'POST',
    'url': '/',
    'headers': [
        ['Host', 'example.com'],
    ],
    'body': '{"this_is": "a_request_body"}',
}

escher = Escher('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
signed_request = escher.sign_request(request)

from pprint import pprint
pprint(signed_request)

Signing a Requests request:

import requests
from escherauth import EscherRequestsAuth

auth = EscherRequestsAuth('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
response = requests.post('https://httpbin.org/post', json={'this_is': 'a_request_body'}, auth=auth)

from pprint import pprint
pprint(response.json())

Presigning a URL

In some cases you may want to send authenticated requests from a context where you cannot modify the request headers, e.g. when embedding an API generated iframe.

You can however generate a presigned URL, where the authentication information is added to the query string.

from escherauth import Escher

escher = Escher('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
presigned_url = escher.presign_url('http://example.com/', expires=300)

print(presigned_url)

Validating a request

You can validate a request signed by the methods described above. For that you will need a database of the access keys and secrets of your clients.

from escherauth import Escher, EscherException

escher = Escher('', '', 'example/credential/scope')

signed_request = {
    'body': '{"this_is": "a_request_body"}',
    'headers': [
        ['Host', 'example.com'],
        ['X-Escher-Date', '20240227T121443Z'],
        ['X-Escher-Auth', 'ESR-HMAC-SHA256 Credential=YOUR_ACCESS_KEY_ID/20240227/example/credential/scope, SignedHeaders=host;x-escher-date, Signature=5febb099193b8e6c4027ff810e0faa5bc8a275efb46f2d5c1af8810f4332c4cb'],
    ],
    'method': 'POST',
    'url': '/',
}
key_db = {
    'ACCESS_KEY_OF_CLIENT_1': 'SECRET OF CLIENT 1',
    'ACCESS_KEY_OF_CLIENT_42': 'SECRET OF CLIENT 42',
}

try:
    escher.authenticate(signed_request, key_db)
    print('OK')
except EscherException as e:
    print(f'The validation failed: {e}')

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

escherauth-1.0.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

escherauth-1.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file escherauth-1.0.2.tar.gz.

File metadata

  • Download URL: escherauth-1.0.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for escherauth-1.0.2.tar.gz
Algorithm Hash digest
SHA256 403d9e28989a288403734b612fc1c1cd05925bd9162253db6154ab57bcc7a6d9
MD5 28e0be25c5227917811227e51b0f3161
BLAKE2b-256 58714a1344e95c15f6676bad86306df2bb624ce5dc6d9c7d381b6b71cb365be9

See more details on using hashes here.

File details

Details for the file escherauth-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: escherauth-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for escherauth-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27ece16d28379076780bd42d81a5f4aceccb3b6ae1e4145e1b088020c295c36c
MD5 7784b6ee8d9ed802f526dc95725ac831
BLAKE2b-256 c539f9c00a3e86bcfbd0d76a2b04d5f7549c0662a7dd9c49b0916218a9903a1b

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