Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions common/src/main/java/org/keycloak/common/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public enum Feature {

FIPS("FIPS 140-2 mode", Type.DISABLED_BY_DEFAULT),

FAPI_V2("FAPI 2.0 Security Profile", Type.EXPERIMENTAL),

DPOP("OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer", Type.DEFAULT),

DEVICE_FLOW("OAuth 2.0 Device Authorization Grant", Type.DEFAULT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.keycloak.OAuth2Constants;
import org.keycloak.OAuthErrorException;
import org.keycloak.common.ClientConnection;
import org.keycloak.common.Profile;
import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder;
import org.keycloak.http.HttpRequest;
Expand Down Expand Up @@ -145,14 +146,18 @@ public Response processGrantRequest() {

checkParameters();

// The token endpoint must return an error if a valid request is sent without a holder of key mechanism (i.e. without DPoP / MTLS).
// https://github.com/keycloak/keycloak/issues/48069
boolean dpopRequired = Profile.isFeatureEnabled(Profile.Feature.FAPI_V2);

/*
* To request an access token that is bound to a public key using DPoP, the client MUST provide a valid DPoP
* proof JWT in a DPoP header when making an access token request to the authorization server's token endpoint.
* This is applicable for all access token requests regardless of grant type (e.g., the common
* authorization_code and refresh_token grant types and extension grants such as the JWT
* authorization grant [RFC7523])
*/
DPoPUtil.handleDPoPHeader(session, event, cors, clientConfig);
DPoPUtil.handleDPoPHeader(session, event, cors, clientConfig, dpopRequired);

OAuth2GrantType.Context context = new OAuth2GrantType.Context(session, clientConfig, clientAuthAttributes,
formParams, event, cors, tokenManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Response request() {
}

// https://datatracker.ietf.org/doc/html/rfc9449#section-10.1
DPoPUtil.handleDPoPHeader(session, event, cors, null);
DPoPUtil.handleDPoPHeader(session, event, cors, null, false);

try {
authorizationRequest = ParEndpointRequestParserProcessor.parseRequest(event, session, client, decodedFormParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public static Stream<Map.Entry<ProtocolMapperModel, ProtocolMapper>> getTransien
public static void handleDPoPHeader(KeycloakSession keycloakSession,
EventBuilder event,
Cors cors,
OIDCAdvancedConfigWrapper clientConfig) {
OIDCAdvancedConfigWrapper clientConfig,
boolean dpopRequired) {

if (!Profile.isFeatureEnabled(Profile.Feature.DPOP)) {
return;
}
Expand All @@ -150,6 +152,15 @@ public static void handleDPoPHeader(KeycloakSession keycloakSession,
final String dpopHeaderValue = request.getHttpHeaders().getHeaderString(DPOP_HTTP_HEADER);
final boolean isDpopHeaderPresent = dpopHeaderValue != null;

// The token endpoint must return an error if a valid request is sent without a holder of key mechanism (i.e. without DPoP / MTLS).
// https://github.com/keycloak/keycloak/issues/48069
if (dpopRequired && !isDpopHeaderPresent) {
String errorMessage = "Proof of key possession DPoP is required";
event.detail(Details.REASON, errorMessage);
event.error(Errors.INVALID_DPOP_PROOF);
throw new CorsErrorResponseException(cors, OAuthErrorException.INVALID_REQUEST, errorMessage, Response.Status.BAD_REQUEST);
}

if (!isClientRequiresDpop && !isDpopHeaderPresent) {
return;
}
Expand Down
Loading