PKCE Code Verifier and Challenge Generator

1.0.3 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

import pkce

# Generate a code verifier and code challenge pair
code_verifier, code_challenge = pkce.generate_pkce_pair()
print(f"Code Verifier: {code_verifier}")
print(f"Code Challenge: {code_challenge}")

# Alternatively, generate separately
single_code_verifier = pkce.generate_code_verifier(length=128)
single_code_challenge = pkce.get_code_challenge(single_code_verifier)
print(f"\nSingle Code Verifier: {single_code_verifier}")
print(f"Single Code Challenge: {single_code_challenge}")

view raw JSON →