@danhachuel/thunderbolt 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,16 +11,36 @@ import requests
11
11
 
12
12
  AUTHORIZE_URL = "https://www.canva.com/api/oauth/authorize"
13
13
  TOKEN_URL = "https://api.canva.com/rest/v1/oauth/token"
14
+ _PKCE_MIN_LENGTH = 43
15
+ _PKCE_MAX_LENGTH = 128
14
16
 
15
17
 
16
18
  def _b64(value: bytes) -> str:
17
19
  return base64.urlsafe_b64encode(value).rstrip(b"=").decode("ascii")
18
20
 
19
21
 
20
- def create_pkce_pair() -> tuple[str, str]:
21
- verifier = _b64(secrets.token_bytes(64))
22
+ def generate_code_verifier() -> str:
23
+ """Create a RFC 7636 verifier using a cryptographically secure source."""
24
+ verifier = _b64(secrets.token_bytes(32))
25
+ if not _PKCE_MIN_LENGTH <= len(verifier) <= _PKCE_MAX_LENGTH:
26
+ raise RuntimeError("Falha ao gerar um code_verifier PKCE válido.")
27
+ return verifier
28
+
29
+
30
+ def generate_code_challenge(code_verifier: str) -> str:
31
+ """Derive the S256 Base64URL-without-padding PKCE challenge."""
32
+ verifier = str(code_verifier or "")
33
+ if not _PKCE_MIN_LENGTH <= len(verifier) <= _PKCE_MAX_LENGTH:
34
+ raise ValueError("code_verifier PKCE inválido.")
22
35
  challenge = _b64(hashlib.sha256(verifier.encode("ascii")).digest())
23
- return verifier, challenge
36
+ if challenge == "<CODE_CHALLENGE>":
37
+ raise RuntimeError("Foi detectado um placeholder de code_challenge.")
38
+ return challenge
39
+
40
+
41
+ def create_pkce_pair() -> tuple[str, str]:
42
+ verifier = generate_code_verifier()
43
+ return verifier, generate_code_challenge(verifier)
24
44
 
25
45
 
26
46
  def create_state() -> str:
@@ -28,6 +48,8 @@ def create_state() -> str:
28
48
 
29
49
 
30
50
  def authorization_url(client_id: str, redirect_uri: str, scope: str, state: str, code_challenge: str) -> str:
51
+ if not code_challenge or code_challenge == "<CODE_CHALLENGE>":
52
+ raise ValueError("Não é permitido iniciar Canva com code_challenge placeholder.")
31
53
  params = {
32
54
  "code_challenge": code_challenge,
33
55
  "code_challenge_method": "S256",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.5.01",
3
+ "version": "0.5.2",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",