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>
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
Release history Release notifications | RSS feed
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.0.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file dciauth-2.0.0.tar.gz
.
File metadata
- Download URL: dciauth-2.0.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c2bec1ce6168ab4ac47e11b027835f43c248e9c2888a9bca2ce2f9e9b27e3ca |
|
MD5 | e0fb699222c2fd1e8da99821b795f662 |
|
BLAKE2b-256 | 7e12b83493b9d6a6e8e0ab37571cd5b48c9bfd6f6fddc54e2eb68d24b13e9409 |
File details
Details for the file dciauth-2.0.0-py2-none-any.whl
.
File metadata
- Download URL: dciauth-2.0.0-py2-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3094b716936761357b009cb5fe1934166e4734f4c50bc96d694386b44def3a5e |
|
MD5 | 5ea5546199af628d302d7618bc5b99a3 |
|
BLAKE2b-256 | 1e54f5ee03444275a1db0f19c62c34b8b1839f95f9512faf5314110b0d291b34 |