Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix code_verifier_length #215

Open
wants to merge 1 commit into
base: versione-corrente
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions static/pkce.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import hashlib
import base64
import re
import os
import random
import secrets
import string

# https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
def get_pkce(code_challenge_method: str = "S256", code_challenge_length: int = 64):
hashers = {"S256": hashlib.sha256}
code_verifier_length = random.randint(43, 128)
code_verifier = base64.urlsafe_b64encode(os.urandom(code_verifier_length)).decode("utf-8")
code_verifier = re.sub("[^a-zA-Z0-9]+", "", code_verifier)
alpha = string.ascii_letters + string.digits + "-._~"
code_verifier_length = secrets.choice(range(43, 128 + 1))
code_verifier = "".join([secrets.choice(alpha) for _ in range(code_verifier_length)])

code_challenge = hashers.get(code_challenge_method)(
code_verifier.encode("utf-8")
Expand Down
Loading