Registry / auth-security / macaroonbakery

macaroonbakery

JSON →
library1.3.4pypypi✓ verified 85d ago

macaroonbakery is a Python library that provides higher-level operations for working with macaroons, building upon the core `pymacaroons` library. It implements the httpbakery conventions, allowing for automatic gathering of discharge macaroons for third-party caveats. The library is currently at version 1.3.4 and, while listed as '2 - Pre-Alpha' on PyPI, shows recent activity on its GitHub repository, suggesting active maintenance.

pip install macaroonbakery
INSTALL
IMPORT
SIG · MACAROONBAKERY
M
macaroonbakery
auth-securitypythonv1.3.4
Install
3.3s avg
Import
846ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.992s · 32.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.3s · import 0.701s · 34MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

httpbakery
from macaroonbakery import httpbakery
The primary module for interacting with the HTTP bakery.
BakeryAuth
from macaroonbakery.httpbakery import BakeryAuth
The class used for authenticating requests with macaroon bakery.

This quickstart demonstrates how to use `macaroonbakery.httpbakery.BakeryAuth` to interact with a protected URL. It automatically manages the acquisition and storage of macaroons using a `RequestsCookieJar`. The `PROTECTED_URL` should be replaced with an actual endpoint that uses macaroon-based authentication. The first request might trigger a redirection to an authentication provider, which `BakeryAuth` is designed to handle.

import requests from macaroonbakery import httpbakery import os # A placeholder for a URL protected by a macaroon bakery service. # In a real application, this would be a URL to your service. PROTECTED_URL = os.environ.get('MACAROON_PROTECTED_URL', 'http://localhost:8080/protected') # Initialize a RequestsCookieJar to store macaroons jar = requests.cookies.RequestsCookieJar() try: # Make a request using BakeryAuth. It will handle macaroon acquisition. # For the first request, it might redirect to an authentication service. resp = requests.get( PROTECTED_URL, cookies=jar, auth=httpbakery.BakeryAuth(cookies=jar) ) resp.raise_for_status() # Raise an exception for HTTP errors print(f"Successfully accessed {PROTECTED_URL}. Response: {resp.text[:100]}...") # Subsequent requests will reuse the macaroons in the jar except requests.exceptions.HTTPError as e: print(f"HTTP Error: {e.response.status_code} - {e.response.text}") except requests.exceptions.RequestException as e: print(f"Request failed: {e}")
Debug
Known issues
gotchaThe library's PyPI status is '2 - Pre-Alpha', indicating that its API may not be stable and could change without adhering to strict semantic versioning. Users should expect potential breaking changes in minor or patch releases.
fix
Review release notes for each update. Pin to exact versions for production use and thoroughly test upgrades.
affects: All versions
gotchamacaroonbakery relies heavily on `pymacaroons` for its core macaroon functionality. The `pymacaroons` library appears to be less actively maintained (last release Feb 2018), which could limit new features or delay critical updates for macaroonbakery.
fix
Be aware of the upstream dependency's status. Monitor both macaroonbakery and pymacaroons for updates or potential issues.
affects: All versions
gotchaWhile `setup.py` indicates compatibility with Python 2.7, modern Python development primarily targets Python 3. Using `macaroonbakery` with Python 2.7 might lead to compatibility issues with other libraries or a lack of future support.
fix
It is strongly recommended to use `macaroonbakery` with Python 3.5+ to ensure compatibility and benefit from ongoing support.
affects: <=1.3.4 (Python 2.7)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'macaroonbakery'
The 'macaroonbakery' Python package is not installed in your current environment, or the Python interpreter cannot find it.
fix
Install the library using pip: `pip install macaroonbakery`
from macaroonbakery import httpbakery
This is a common search query when users are looking for the correct way to import the `httpbakery` module from the `macaroonbakery` library, often after an `ModuleNotFoundError` or when trying to understand basic usage.
fix
Ensure the library is installed (`pip install macaroonbakery`) and the import statement is correct: `from macaroonbakery import httpbakery`
invalid macaroon signature
The macaroon being presented for authentication is either malformed, has been tampered with, is expired, or its signature does not match what the verifying service expects, indicating an issue with its validity or origin.
fix
Verify that the macaroon (or the API token leveraging macaroons) was correctly generated, has not expired, and is being used within its intended scope. Regenerate the macaroon if there are doubts about its integrity or validity.
requests.get(...) auth=httpbakery.BakeryAuth(cookies=jar) fails
The `httpbakery.BakeryAuth` object or the cookie jar (`requests.cookies.RequestsCookieJar`) might not be correctly initialized or consistently passed across requests, leading to authentication failures or an inability to obtain/use discharge macaroons.
fix
Ensure `jar = requests.cookies.RequestsCookieJar()` is initialized once and consistently passed to `httpbakery.BakeryAuth(cookies=jar)` for all relevant `requests` calls to maintain the session and handle macaroons.
Upgrade
Version history
1.3.4latest on PyPI · released Dec 13, 2023
Audit
Dependencies
requestsrequiredUsed for HTTP interactions, especially with BakeryAuth.
PyNaClrequiredPython bindings to libsodium, a cryptographic library.
pymacaroonsrequiredCore macaroon implementation that macaroonbakery builds upon.
sixrequiredPython 2 and 3 compatibility library.
protobufrequiredUsed for Protocol Buffer serialization/deserialization.
pyRFC3339requiredParser and generator of RFC 3339-compliant timestamps.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
macaroonbakery — pip install macaroonbakery · libregistry