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 2 in DCI. The algorithm used by dciauth is identical to Signature Version 4 in AWS.

Authentication example:

Create a HmacAuthBase object to give to python requests module

from dciauth.signature import HmacAuthBase

auth = HmacAuthBase(
    access_key="access_key",
    secret_key="secret_key",
    region="us-east-1",
    service="api",
    service_key="aws4_request",
    algorithm="AWS4-HMAC-SHA256",
)

GET

import requests

requests.get("http://api.distributed-ci.io/api/v1/jobs", auth=auth)

POST

import requests

requests.post("http://api.distributed-ci.io/api/v1/users", auth=auth, json={"name": "user 1"})

Validation example

import flask
from dciauth.signature import FlaskHmacSignature

@app.route("/api/protected", methods=["GET"])
def get_protected():
    auth_scheme = flask.request.headers.get("Authorization").split(" ")[0]
    if auth_scheme == "AWS4-HMAC-SHA256":
        signature = FlaskHmacSignature(
            {
                "service_name": "api",
                "service_key": "aws4_request",
                "region_name": "us-east-1",
                "algorithm": "AWS4-HMAC-SHA256",
            }
        ).add_request(flask.request)
        assert signature.access_key == "access_key"
        if not signature.is_valid(secret_key="secret_key"):
            return "ko", 401
        return "ok", 200
    return "ko", 400

Using POSTMAN

If you are using POSTMAN to discover DCI API you can use the following parameters with the AWS Signature authorization header:

GET https://api.distributed-ci.io/api/v1/identity
AccessKey=<DCI_CLIENT_ID>
SecretKey=<DCI_API_SECRET>
AWS Region="BHS3"
Service Name="api"

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-4.0.0.post202410241336.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

dciauth-4.0.0.post202410241336-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file dciauth-4.0.0.post202410241336.tar.gz.

File metadata

File hashes

Hashes for dciauth-4.0.0.post202410241336.tar.gz
Algorithm Hash digest
SHA256 85a2c3b00c9b9a59f6d13b0b74df5be808f28187d7808bd077f19f159b0a7561
MD5 a27190998d62247ad10953d3bfe9e8aa
BLAKE2b-256 bab393eb45a300264b0e971058f3ad6711f122600cd5aac9346140a20505b807

See more details on using hashes here.

File details

Details for the file dciauth-4.0.0.post202410241336-py3-none-any.whl.

File metadata

File hashes

Hashes for dciauth-4.0.0.post202410241336-py3-none-any.whl
Algorithm Hash digest
SHA256 48f1945c6d245c8ae3c4220394916bf5b58b4e45cbbc073045fb4f68ad6a7f8e
MD5 497384aff0bd8f6c6c52fa150c786023
BLAKE2b-256 a412c13cc254c35dd3faacd6071a2920062b2cdc35a89387dc79850977737d82

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