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.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

dciauth-2.0.2-py2-none-any.whl (7.0 kB view details)

Uploaded Python 2

File details

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

File metadata

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

File hashes

Hashes for dciauth-2.0.2.tar.gz
Algorithm Hash digest
SHA256 86df93a719507d424edaca170e1ed1d4ee716cc6917e16e065f1a996fba8e158
MD5 ddb8d6fc7244a7449f90b89deae0a60b
BLAKE2b-256 a5168fbbffe6eff93c0bf1b63c997b0e57842e88b0fac1e79b362bb12691f5ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dciauth-2.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 484d9d95b2f794247a7e9e693774c7a9ae174e67994e3fd100a27c275c935c13
MD5 f33446dde49be8cbb13fc7287deb03cb
BLAKE2b-256 40e7774f1efad03043b64568a9cac0db1429869d9faa12444279ba4ceb454fcc

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