epikulski / httpx-iap

A httpx custom authentication class for Google IAP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A httpx custom authentication class for Google IAP

License:MIT License


Languages

Language:Python 94.0%Language:Makefile 6.0%