0Pricing
Spring Security 6 & JWT Authentication · Lektion

PKCE und die Absicherung öffentlicher Clients

Lernen Sie, wie die PKCE-Erweiterung den OAuth2 Authorization Code Flow für mobile Apps und Single-Page-Apps schützt, die kein Client Secret sicher verwahren können.

PKCE und die Absicherung öffentlicher Clients ist eine kostenlose Spring Security 6 & JWT Authentication-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Security 6 & JWT Authentication-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Security 6 & JWT Authentication-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

The Public Client Problem

Mobile apps and SPAs are public clients: their code ships to the user, so they cannot safely store a client secret. Without a secret, the plain Authorization Code flow is vulnerable to interception.

What PKCE Solves

PKCE (Proof Key for Code Exchange, pronounced 'pixy') adds a dynamic secret per authorization request. Even if the authorization code is stolen, it cannot be exchanged without the matching proof.

The Code Verifier

The client generates a random, high-entropy string called the code_verifier and keeps it in memory for this one flow.

const codeVerifier = base64url(randomBytes(32));

The Code Challenge

The client hashes the verifier with SHA-256 to make the code_challenge. The hash is sent to the server, but the original verifier never leaves the device yet.

const codeChallenge = base64url(sha256(codeVerifier));

Starting the Authorization Request

The client sends the challenge and the method (S256) to the authorization endpoint along with the usual parameters.

GET /authorize?response_type=code
  &client_id=app123
  &code_challenge=XYZ...
  &code_challenge_method=S256

Server Stores the Challenge

The authorization server remembers the code_challenge and links it to the authorization code it issues after the user logs in.

Exchanging the Code

When swapping the code for tokens, the client now reveals the original code_verifier.

POST /token
  grant_type=authorization_code
  &code=abc123
  &code_verifier=ORIGINAL_RANDOM

Server Verifies the Proof

The server hashes the received verifier and compares it to the stored challenge. If they match, the requester is the same party that started the flow; otherwise it rejects the exchange.

if (sha256(received_verifier) !== stored_challenge) {
  reject('invalid_grant');
}

Why It Stops Interception

An attacker who steals the authorization code (for example via a malicious app on the device) still cannot use it: they never saw the code_verifier, which existed only inside the legitimate client's memory.

PKCE Is Now Recommended for All

Originally for mobile, PKCE is now recommended for every Authorization Code flow, including confidential web clients. OAuth 2.1 makes it the default.

Library Support

You rarely implement PKCE by hand. Libraries like AppAuth, oidc-client-ts, and Spring Authorization Server handle verifier generation, hashing, and validation for you.

Quick Check

Test your understanding of PKCE.

Recap

You learned how PKCE secures public clients:

  • Public clients cannot keep a secret, so the plain code flow is unsafe
  • The client creates a code_verifier and sends its hash as the code_challenge
  • The verifier is revealed only at token exchange
  • A stolen code is useless without the verifier

PKCE is now the default for all Authorization Code flows.

Häufig gestellte Fragen

Ist die Lektion „PKCE und die Absicherung öffentlicher Clients“ kostenlos?

Ja — der vollständige Text von „PKCE und die Absicherung öffentlicher Clients“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Security 6 & JWT Authentication-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Security 6 & JWT Authentication-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „PKCE und die Absicherung öffentlicher Clients“?

Lernen Sie, wie die PKCE-Erweiterung den OAuth2 Authorization Code Flow für mobile Apps und Single-Page-Apps schützt, die kein Client Secret sicher verwahren können. Du übst Spring Security 6 & JWT Authentication mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Spring Security 6 & JWT Authentication zu starten?

Keine Vorkenntnisse erforderlich. Spring Security 6 & JWT Authentication auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „PKCE und die Absicherung öffentlicher Clients“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Spring Security 6 & JWT Authentication-Lektion Code schreiben und ausführen?

Ja. Jede Spring Security 6 & JWT Authentication-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Überblick über das OAuth2-Protokoll
  2. Einführung in OpenID Connect
  3. Gängige OAuth2-Grant-Typen
  4. PKCE und die Absicherung öffentlicher Clients
← Zurück zu Spring Security 6 & JWT Authentication