Registry / auth-security / python3-openid

python3-openid

JSON →
library3.2.0pypypi✓ verified 87d ago

python3-openid provides OpenID 1.x and 2.0 support for modern Python 3 servers and consumers. The current version is 3.2.0. The release cadence is slow, focusing on compatibility and maintenance rather than active feature development for new OpenID versions.

pip install python3-openid
INSTALL
IMPORT
SIG · PYTHON3-OPENID
P
python3-openid
auth-securitypythonv3.2.0
Install
1.7s avg
Import
217ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.0 · 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.925 runs
installs and imports cleanly · install 0.0s · import 0.227s · 18.9MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.7s · import 0.208s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

Consumer
from openid.consumer import consumer
from openid.consumer.consumer import Consumer
The 'consumer' module itself holds the Consumer class. Direct import from the module is generally preferred.
Server
from openid.server import server
from openid.server.server import Server
Similar to Consumer, the 'server' module holds the Server class.
FileOpenIDStore
from openid.store import filestore
import openid.store.filestore.FileOpenIDStore
FileOpenIDStore is within the 'filestore' module of the 'store' package.

This quickstart demonstrates initiating an OpenID consumer authentication flow. It initializes a Consumer object with a file-based store (not for production) and attempts to begin an authentication request for a placeholder OpenID URL. In a real web application, the `auth_request.redirectURL` would be used to redirect the user's browser to the OpenID Provider.

import os from openid.consumer import consumer from openid.store import filestore # Create a file store for nonces and associations (NOT suitable for production) store_path = "openid_store" os.makedirs(store_path, exist_ok=True) store = filestore.FileOpenIDStore(store_path) # Initialize the consumer oid_consumer = consumer.Consumer(store) # Example: Begin OpenID authentication (conceptual example for a web app flow) # In a real web application, this would involve user input and HTTP redirects. user_openid_url = "https://openid.example.com/user/alice" # Replace with an actual OpenID Provider URL try: # This call prepares an authentication request. # The actual redirect to the OpenID Provider (OP) happens in a web framework. auth_request = oid_consumer.begin(user_openid_url) # Simulate the redirect URL generation (in a real app, this would be returned to the client) return_to_url = 'http://localhost:8000/verify' trust_root = 'http://localhost:8000' print(f"OpenID authentication initiated for {user_openid_url}") print(f"User should be redirected to: {auth_request.redirectURL(return_to_url, trust_root)}") except consumer.DiscoveryFailure as e: print(f"OpenID discovery failed for {user_openid_url}: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") # For demonstration purposes, you might clean up the store directory # import shutil # shutil.rmtree(store_path)
Debug
Known issues
breakingThe `python-openid` library (for Python 2) is distinct from `python3-openid` (for Python 3). While the internal `openid` package namespace is largely consistent, direct dependencies or custom integrations built for Python 2's `python-openid` will require careful migration.
fix
Ensure you are installing `python3-openid` on PyPI for Python 3 projects. Review any direct imports or interactions with the library's internal structure that might have changed between Python 2 and Python 3 standard library behavior.
affects: All versions (migration from Python 2)
gotchaThe default `openid.store.filestore.FileOpenIDStore` is not suitable for production environments. It lacks support for concurrency, distributed systems, and often requires specific file permissions, making it unreliable for web applications.
fix
For production, implement a custom store (inheriting from `openid.store.interface.OpenIDStore`) that uses a robust database (e.g., PostgreSQL, MySQL) or a distributed key-value store (e.g., Redis). Consider using existing community-contributed store implementations if available for your chosen backend.
affects: All versions
gotchaThe OpenID 1.x/2.0 protocol, which `python3-openid` implements, is an older standard. For new authentication needs, consider modern alternatives like OpenID Connect (OIDC), which is built on OAuth 2.0 and offers more features, better security practices, and broader adoption.
fix
Evaluate your project's authentication requirements carefully. If OpenID 2.0 is specifically required for integration with existing providers, this library is appropriate. For new implementations, research OpenID Connect libraries and providers instead.
affects: All versions (contextual)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'openid'
The 'python3-openid' package is not installed or is not accessible in the current Python environment.
fix
Install the library using pip: `pip install python3-openid`
AttributeError: module 'openid.consumer' has no attribute 'begin'
The 'begin' method is part of an instance of the `openid.consumer.Consumer` class, not directly accessible from the module itself.
fix
First, instantiate the `Consumer` class: `consumer = openid.consumer.Consumer(store, request_params)`. Then, call the method on the instance: `auth_request = consumer.begin(identity_url, return_to_url, realm)`.
ValueError: The return_to URL must be under the realm's control.
The `return_to` URL specified in the OpenID authentication request is not within the domain or path controlled by the `realm` URL, violating OpenID security requirements.
fix
Ensure the `return_to` URL is a sub-path or on the same domain as the `realm` URL, or adjust the `realm` to encompass the `return_to` URL's domain.
openid.yadis.discover.DiscoveryFailure: No OpenID information found.
The provided identity URL does not contain the necessary OpenID discovery information (e.g., `<link>` tags for OpenID 1.x or XRDS document for OpenID 2.0).
fix
Verify that the identity URL is correct and points to a valid OpenID provider, and that the provider's page correctly publishes OpenID discovery metadata.
AttributeError: 'str' object has no attribute 'get'
This error typically occurs when the `query_args` parameter passed to `openid.consumer.Consumer.complete()` is expected to be a dictionary-like object (e.g., from a web request's GET/POST parameters), but a string or other non-dictionary type was provided.
fix
Ensure `query_args` is a dictionary or a dictionary-like object containing the OpenID response parameters, commonly obtained from your web framework's `request.GET` or `request.POST`.
Upgrade
Version history
3.2.0latest on PyPI · released Jun 29, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
1
Resources
python3-openid — pip install python3-openid · libregistry