Library of common utils for interacting with Identity-Aware Proxies
Project description
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_client_id="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,
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 example1(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)
# 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iaptoolkit-0.3.0.tar.gz
(10.0 kB
view details)
Built Distribution
File details
Details for the file iaptoolkit-0.3.0.tar.gz
.
File metadata
- Download URL: iaptoolkit-0.3.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a16933011a920b3420bae15433a42fe963dd21c31313d8cbc14c0572fbca910 |
|
MD5 | 9eb4bd1714d2b53b28526658af326282 |
|
BLAKE2b-256 | 03ea66c7e448e78d59eb00c4b5bd04d30bd9dcc0744fb86f18d91ea3a660aa76 |
File details
Details for the file iaptoolkit-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: iaptoolkit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf8304652059e3c01f25b2bf4e9ada72683898718ed35c6f98ddd199e9c0632 |
|
MD5 | cb8087befcd2e6d7d86f57b8c0947fd9 |
|
BLAKE2b-256 | 52b601bce42d4b82717977258940ea88d1c8fe85fa4ac59a008ab1d297188bf8 |