IAP Toolkit
A library of utils to ease programmatic authentication with Google IAP (and ideally other IAPs in future).
PyPi
https://pypi.org/project/iaptoolkit/
Installation
With Poetry:
poetry add iaptoolkit
With pip:
pip install iaptoolkit
Quick Start / Example Usage
import requests
from iaptoolkit import IAPToolkit
iaptk = IAPToolkit(google_iap_audience="EXAMPLE_ID_123456789ABCDEF")
allowed_domains = ["example.com", ]
# Example #1 - Combined Calls
def example1(url: str):
headers = dict()
result = iaptk.check_url_and_add_token_header(
url=url,
request_headers=headers,
iap_audience="some_iap_audience_string" # OAuth Client ID for the IAP-protected resource as 'audience'
valid_domains=allowed_domains
)
# result.token_added (bool) indicates if the token was added, depending on whether or not URL was valid
# headers dict now contains the appropriate Bearer Token header for Google IAP
# Make HTTP GET request with requests lib, with our headers containing bearer token to auth with IAP
response = requests.request("GET", url, headers=headers)
# Example #2 - Separate Calls - Functionally the same as Example 1 but more flexibility in URL validation
def example2(url: str):
is_url_safe: bool = iaptk.is_url_safe_for_token(url=url, valid_domains=valid_domains)
if not is_url_safe:
raise ExampleBadURLException("This URL isn't safe to send token headers to!")
headers = dict()
token_is_fresh: bool = iaptk.get_token_and_add_to_headers(
request_headers=headers,
iap_audience="some_iap_audience_string" # OAuth Client ID for the IAP-protected resource as 'audience'
)
# token_is_fresh indicates if token was newly retrieved (True), or if a cached token was reused (False)
# headers dict now contains the appropriate Bearer Token header for Google IAP
# Make HTTP GET request with requests lib, with our headers containing bearer token to auth with IAP
response = requests.request("GET", url, headers=headers)
# Example #3 - Service Account JWT (instead of OIDC Token)
def example3(url: str):
headers = dict()
result = iaptk.check_url_and_add_jwt_header(
url=url,
request_headers=headers,
service_account_email="service-account@PROJECT_ID.iam.gserviceaccount.com",
url_audience="https://some-iap-protected.resource/path",
valid_domains=allowed_domains
)
# result.token_added (bool) indicates if the token was added, depending on whether or not URL was valid
# headers dict now contains the appropriate Bearer JWT header for Google IAP
# Make HTTP GET request with requests lib, with our headers containing bearer token to auth with IAP
response = requests.request("GET", url, headers=headers)
# Example #4 - Separate Calls - Service Account JWT - Functionally the same as Example 3 but more flexibility in URL validation
def example4(url: str):
is_url_safe: bool = iaptk.is_url_safe_for_token(url=url, valid_domains=valid_domains)
if not is_url_safe:
raise ExampleBadURLException("This URL isn't safe to send token headers to!")
headers = dict()
token_is_fresh: bool = iaptk.get_jwt_and_add_to_headers(
request_headers=headers,
service_account_email="service-account@PROJECT_ID.iam.gserviceaccount.com",
url_audience="https://some-iap-protected.resource/path"
)
# token_is_fresh indicates if token was newly retrieved (True), or if a cached token was reused (False)
# headers dict now contains the appropriate Bearer Token header for Google IAP
# Make HTTP GET request with requests lib, with our headers containing bearer token to auth with IAP
response = requests.request("GET", url, headers=headers)
Disclaimer
This project is not affiliated with Google. No trademark infringement intended.
Release files for iaptoolkit 0.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| iaptoolkit-0.5.3.tar.gz | 12.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iaptoolkit-0.5.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:28.5 kB
Release files / iaptoolkit-0.5.3.tar.gz
| Download URL | iaptoolkit-0.5.3.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5ec6ca83b532e07a9734f42f1a322beb508cb8126dfa56ab33a58113495a154
|
|
BLAKE2b-256 checksum How to use checksums |
36e057521cac47fa8077a477b3bf7268dc13eb2c0e12a69b64ef293d550e5577
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.
Transparency logRelease files / iaptoolkit-0.5.3-py3-none-any.whl
| Download URL | iaptoolkit-0.5.3-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fd52fab82966b924c823ce64e6fc41236e1ce43f30c8b8cb6fa259c9cdd7188
|
|
BLAKE2b-256 checksum How to use checksums |
1382c7fec11c26cd1505c1ea2758e5b90f7547be28db38935a43711be26ba82b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.
Transparency log