Skip to main content

DCI authentication module used by dci-control-server and python-dciclient

Project description

# python-dciauth

DCI authentication module used by dci-control-server and python-dciclient

This section shows example programs written in python that illustrate how to work with Signature Version 4 in DCI. The algorithm used by dciauth is similar to [Signature Version 4 in AWS](http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html).

## Signing example:

```python
import requests

from dciauth.signature import Signature
from dciauth.request import AuthRequest

auth_request = AuthRequest(endpoint='/api/v1/jobs')
headers = Signature(request=auth_request).generate_headers('remoteci', 'client_id', 'secret')
r = requests.get('http://127.0.0.1:5000/api/v1/jobs', headers=headers)
assert r.status_code == 200
```

Here we are signing the GET request with `secret` and generate headers used by `requests` module.

## Validation example


```python
from flask import request

from dciauth.signature import Signature
from dciauth.request import AuthRequest

auth_request = AuthRequest(
method=request.method,
endpoint=request.path,
payload=request.get_json(silent=True),
headers=request.headers,
params=request.args.to_dict(flat=True)
)
signature = Signature(request=auth_request)
if not signature.is_valid('secret'):
raise Exception("Authentication failed: signature invalid")
if signature.is_expired():
raise Exception("Authentication failed: signature expired")
```

## License

Apache 2.0


## Author Information

Distributed-CI Team <distributed-ci@redhat.com>


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

dciauth-2.0.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

dciauth-2.0.1-py2-none-any.whl (6.9 kB view details)

Uploaded Python 2

File details

Details for the file dciauth-2.0.1.tar.gz.

File metadata

  • Download URL: dciauth-2.0.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dciauth-2.0.1.tar.gz
Algorithm Hash digest
SHA256 26e9152cef26bb31999c644046783e45d5b1ebdf28697ec8a78cee8e4a8dc0db
MD5 40893e261025b11a09e8ccef59613959
BLAKE2b-256 a71287c1b4e2558fd914ef38bcc87e4f5a428c97e0eec2c66f582c1298912868

See more details on using hashes here.

File details

Details for the file dciauth-2.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for dciauth-2.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 4f186ab3df73efa032246c57c6fc2f9db046f9e089eea7607575f2b68226d22a
MD5 682f7a5c8252e63ca0a4e0521acb2abe
BLAKE2b-256 344eb745133e29c516ffcf6242bbaf8d8c628ebd8f045aee6f9255a1eb6c5e46

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