The `pkce` library is a lightweight Python module designed to simplify the generation of Proof Key for Code Exchange (PKCE) code verifiers and code challenges. It provides essential cryptographic helper functions for implementing the PKCE extension to the OAuth 2.0 Authorization Code Flow, particularly important for public clients (like mobile or single-page applications) that cannot securely store a client secret. The current version is 1.0.3, with an infrequent release cadence reflecting its stable and focused functionality.
pip install pkceVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to generate a PKCE code verifier and its corresponding code challenge using the `pkce` library. You can either generate them as a pair or individually, specifying the desired length for the verifier.
Always use the SHA256 (S256) method for code challenge generation. The `pkce` library defaults to S256. Configure your OAuth 2.0 Authorization Server to enforce PKCE for all clients, disallowing the 'plain' method.
Thoroughly review OAuth 2.0 and PKCE best practices (e.g., RFC 7636, OAuth 2.1 security BCPs). Always validate redirect URIs strictly, use a cryptographically strong 'state' parameter to prevent CSRF, and store tokens securely (avoiding local storage for access tokens in browsers).
Integrate `pkce` with a comprehensive OAuth client library (e.g., `requests-oauthlib`, `Authlib`) or implement the HTTP requests and token management logic yourself, ensuring adherence to security best practices for each step of the OAuth flow.
Install the library using pip: `pip install pkce`
Ensure the exact `code_verifier` generated by `pkce.generate_code_verifier()` is stored securely (e.g., in a session) and used consistently to generate the `code_challenge` (via `pkce.generate_code_challenge()`) and later sent unmodified to the token endpoint.
Always use `pkce.generate_code_challenge(code_verifier)` which correctly applies SHA256 hashing and URL-safe base64 encoding without padding, as required by RFC 7636.
No dependency data recorded yet.