Skip to content

A httpx custom authentication class for Google IAP

License

Notifications You must be signed in to change notification settings

epikulski/httpx-iap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpx-iap

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.

Installation

python -m pip install git+https://github.com/epikulski/httpx-iap.git

Usage

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)
    )

Development

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