Skip to content

PKCE

reauth.factors.oauth2.pkce

CodeChallengeMethod module-attribute

CodeChallengeMethod = typing.Literal['S256', 'plain']

generate_code_verifier

generate_code_verifier() -> str

Generate a PKCE code_verifier as per RFC 7636 Section 4.1.

Uses a cryptographically secure random number generator to create a high-entropy string using the unreserved URI character set: ALPHA / DIGIT / "-" / "." / "_" / "~"

Returns:

Type Description
str

A cryptographically random string of ~86 characters, within the

str

RFC 7636 range of 43-128 characters, with 512 bits of entropy.

generate_code_challenge

generate_code_challenge(
    code_verifier: str, method: CodeChallengeMethod
) -> str

Generate a PKCE code_challenge from a code_verifier as per RFC 7636.

Parameters:

Name Type Description Default
code_verifier str

The code verifier string.

required
method CodeChallengeMethod

The code challenge method. Either "S256" or "plain".

required

Returns:

Type Description
str

The code challenge string.