vws-auth-tools¶
Installation¶
pip install vws-auth-tools
This is tested on Python 3.13+.
Example usage¶
VWS and Query APIs¶
"""Make a request to the VWS API."""
import os
from http import HTTPStatus
from urllib.parse import urljoin
import requests
from vws_auth_tools import authorization_header, rfc_1123_date
access_key = os.environ["VWS_SERVER_ACCESS_KEY"]
secret_key = os.environ["VWS_SERVER_SECRET_KEY"]
request_path = "/targets"
content = b""
method = "GET"
formatted_date = rfc_1123_date()
authorization_header_value = authorization_header(
access_key=access_key,
secret_key=secret_key,
method=method,
content=content,
content_type="",
date=formatted_date,
request_path=request_path,
)
headers = {
"Authorization": authorization_header_value,
"Date": formatted_date,
}
response = requests.request(
method=method,
url=urljoin(base="https://vws.vuforia.com", url=request_path),
headers=headers,
data=content,
timeout=30,
)
assert response.status_code == HTTPStatus.OK, response.text
Model Target Web API¶
The Model Target Web API does not use the signature scheme which
authorization_header implements. It authenticates with OAuth2 client
credentials: a POST /oauth2/token request with HTTP Basic credentials
and a grant_type=client_credentials form body returns a bearer token,
which is then sent to the dataset endpoints.
This package builds the headers only. Making the token request, and caching the returned token until it expires, are left to you.
"""Build authorization headers for the Model Target Web API."""
import os
from vws_auth_tools import (
basic_authorization_header,
bearer_authorization_header,
)
client_id = os.environ["VWS_MODEL_TARGET_CLIENT_ID"]
client_secret = os.environ["VWS_MODEL_TARGET_CLIENT_SECRET"]
token_request_headers = {
"Authorization": basic_authorization_header(
client_id=client_id,
client_secret=client_secret,
),
"Content-Type": "application/x-www-form-urlencoded",
}
# Sending ``grant_type=client_credentials`` to ``POST /oauth2/token``
# with those headers returns JSON with an ``access_token`` item.
access_token = "eyJhbGciOiJtb2NrIn0.e30.example-signature" # noqa: S105
dataset_request_headers = {
"Authorization": bearer_authorization_header(
access_token=access_token,
),
}
assert token_request_headers["Authorization"].startswith("Basic ")
assert dataset_request_headers["Authorization"].startswith("Bearer ")
Reference¶
- API Reference
- Contributing to vws-auth-tools
- Release Process
- Unreleased changes
- Changelog
- 2026.08.16
- 2024.07.12
- 2023.03.05
- 2021.12.13.3
- 2021.12.13.1
- 2021.12.12.9
- 2021.12.12.8
- 2021.12.12.8
- 2021.12.12
- 2021.12.12.8
- 2021.12.12.8
- 2021.12.12.7
- 2021.12.12.6
- 2021.12.12.5
- 2021.12.12.4
- 2021.12.12.3
- 2021.12.12.2
- 2021.12.12.1
- 2021.12.12.0
- 2021.12.11.0
- 2021.11.05.0
- 2020.05.31.0
- 2019.12.28.4
- 2019.12.28.3
- 2019.12.28.2
- 2019.12.28.1
- 2019.12.28.0
- 2019.12.27.1
- 2019.12.27.0
- 2019.12.08.2
- 2019.12.08.1
- 2019.12.08.0