A custom authentication class for httpx to interact with applications secured by Google IAP.
Thank you to Jan Masarik for requests-iap
, which this implementation is based upon.
python -m pip install git+https://github.com/epikulski/httpx-iap.git
import json
import httpx
from httpx_iap import IAPAuth
with open("your-google-service-account.json") as fd:
service_account_dict = json.load(fd)
client_id = "your-client-id-12345.apps.googleusercontent.com"
response = httpx.get(
"https://your-iap-protected-service.example.com",
auth=IAPAuth(client_id=client_id, service_account=service_account_dict)
)
The IAPAuth
class is also compatible with httpx.AsyncClient
import json
import httpx
from httpx_iap import IAPAuth
with open("your-google-service-account.json") as fd:
service_account_dict = json.load(fd)
client_id = "your-client-id-12345.apps.googleusercontent.com"
async with httpx.AsyncClient() as client:
response = await client.get(
"https://your-iap-protected-service.example.com",
auth=IAPAuth(client_id=client_id, service_account=service_account_dict)
)
httpx_iap
uses Poetry to manage the development environment. Shortcuts for most development tasks are avaialable
in the project Makefile
# Configure the environment
make init
# Run linting
make lint
# Run tests
make test