Debian Codegraph @

allauth/socialaccount/providers/oauth2/utils.py

raw
1 from __future__ import annotations
2
3 import base64
4 import hashlib
5 from secrets import token_urlsafe
6
7
8 def generate_code_challenge() -> dict:
9 # Create a code verifier with a length of 128 characters
10 code_verifier = token_urlsafe(96)
11 hashed_verifier = hashlib.sha256(code_verifier.encode("ascii"))
12 code_challenge = base64.urlsafe_b64encode(hashed_verifier.digest())
13 code_challenge_without_padding = code_challenge.rstrip(b"=")
14 return {
15 "code_verifier": code_verifier,
16 "code_challenge_method": "S256",
17 "code_challenge": code_challenge_without_padding,
18 }