Skip to main content

Genera Coppia PKCE

Metodo di challenge
Lunghezza code_verifier: 64 caratteri
43 (min)6496128 (max)

RFC 7636 richiede tra 43 e 128 caratteri. Valori tra 64 e 96 sono consigliati.

Come utilizzare PKCE Challenge Generator

Seleziona il metodo di challenge

Scegli "S256" (raccomandato) per generare il code_challenge come hash SHA-256 del code_verifier, codificato in Base64URL. Il metodo "plain" usa il code_verifier direttamente come challenge: da usare solo se il client non supporta SHA-256.

Imposta la lunghezza del code_verifier

Usa il cursore per scegliere la lunghezza del code_verifier tra 43 e 128 caratteri (RFC 7636). Una lunghezza di 64 caratteri offre un ottimo equilibrio tra sicurezza e compatibilità. Più lunga è la stringa, maggiore è l'entropia.

Genera la coppia PKCE

Clicca "Genera" per creare una nuova coppia code_verifier / code_challenge. La generazione avviene interamente nel browser usando l'API Web Crypto: nessun dato viene inviato a server esterni.

Copia i valori e usali nel flusso OAuth 2.0

Copia il code_verifier e conservalo in modo sicuro (es. sessionStorage). Invia il code_challenge al server di autorizzazione nella richiesta iniziale. Al momento dello scambio del codice, invia il code_verifier originale per la verifica.

Consulta il template URL di autorizzazione

La sezione "Flusso OAuth 2.0" mostra un esempio di URL di autorizzazione con i valori generati già inseriti. Sostituisci i segnaposto con i tuoi valori reali (authorization_endpoint, client_id, redirect_uri, scope).

Suggerimenti

  • Genera sempre un nuovo code_verifier per ogni flusso OAuth: non riutilizzare mai lo stesso valore. La freschezza del verifier è parte essenziale della protezione offerta da PKCE.
  • Se il tuo server di autorizzazione lo supporta, preferisci sempre il metodo S256. Alcuni server rifiutano esplicitamente il metodo plain per motivi di sicurezza.
  • Lunghezze di code_verifier comprese tra 64 e 96 caratteri offrono un ottimo compromesso tra sicurezza (alta entropia) e compatibilità con server che limitano la dimensione dei parametri URL.

Domande frequenti

What is PKCE and why is it important?

Proof Key for Code Exchange (PKCE) is an extension of the OAuth 2.0 authorization code flow. Protects public clients (mobile apps, SPAs) from interception attacks on authorization codes. Without PKCE, a malicious app intercepting the code could exchange it for an access token. With PKCE, only the client that generated the code_verifier can complete the exchange.

What is the difference between S256 and plain?

Base64URL(SHA-256(ASCII(code_verifier))). This is the recommended method by RFC 7636 and is required for servers conforming to the latest specifications. The plain method uses the code_verifier directly as challenge and is deprecated; it should only be used if the client cannot perform SHA-256, but this does not offer real additional protection.

How do I store the code verifier?

Code verifier must be generated randomly for each authorization request and stored temporarily (e.g., sessionStorage or in-app memory) until the code exchange time. Do not store it in localStorage as it persists between sessions. Never send it before the code exchange: only the code challenge travels with the first request.

Is this generated code verifier safe for production?

Yes. The generator uses window.crypto.getRandomValues, the same cryptographically secure API used by browsers to generate random numbers. Values are generated only in your browser and never sent to servers. However, this tool is intended for testing and development purposes: in production, the code_verifier must be generated by the client application at every stream start-up.

What characters are allowed in the code verifier?

According to RFC 7636, the code_verifier can only contain "unreserved" URI characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), hyphen (-), period (.), underscore (_), and tilde (~). Length must be between 43 and 128 characters. This generator exactly respects these constraints.

What is Base64URL encoding?

Base64URL is a variant of Base64 designed for use in URLs and HTTP headers without additional encoding. It uses "-" instead of "+" and "_" instead of "/", and omits the "=" padding. The code_challenge in method S256 uses this encoding to represent the SHA-256 digest of the code_verifier.