diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/TokenEndpoint.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/TokenEndpoint.java
index 83a38062ea..a6de745231 100644
--- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/TokenEndpoint.java
+++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/TokenEndpoint.java
@@ -23,7 +23,6 @@ import org.keycloak.http.HttpResponse;
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.models.AuthenticatedClientSessionModel;
@@ -219,12 +218,6 @@ public class TokenEndpoint {
grant = OAuth2GrantManager.resolve(session, grantType).orElseThrow(() -> newUnsupportedGrantTypeException());
event.event(grant.getEventType());
-
- if (grantType.equals(OAuth2Constants.DEVICE_CODE_GRANT_TYPE)
- && !Profile.isFeatureEnabled(Profile.Feature.DEVICE_FLOW)) {
- throw newUnsupportedGrantTypeException();
- }
-
event.detail(Details.GRANT_TYPE, grantType);
}
diff --git a/services/src/main/java/org/keycloak/protocol/oidc/grants/device/DeviceGrantType.java b/services/src/main/java/org/keycloak/protocol/oidc/grants/device/DeviceGrantType.java
index 4392b02f77..ce029e2348 100644
--- a/services/src/main/java/org/keycloak/protocol/oidc/grants/device/DeviceGrantType.java
+++ b/services/src/main/java/org/keycloak/protocol/oidc/grants/device/DeviceGrantType.java
@@ -21,6 +21,7 @@ import static org.keycloak.protocol.oidc.OIDCLoginProtocolService.tokenServiceBa
import org.keycloak.OAuth2Constants;
import org.keycloak.OAuthErrorException;
+import org.keycloak.common.Profile;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder;
@@ -37,11 +38,13 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleUseObjectProvider;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel;
+import org.keycloak.provider.EnvironmentDependentProviderFactory;
import org.keycloak.protocol.LoginProtocol;
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
import org.keycloak.protocol.oidc.TokenManager;
import org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint;
+import org.keycloak.protocol.oidc.grants.OAuth2GrantType;
import org.keycloak.protocol.oidc.grants.OAuth2GrantTypeBase;
import org.keycloak.protocol.oidc.grants.device.clientpolicy.context.DeviceTokenRequestContext;
import org.keycloak.protocol.oidc.grants.device.clientpolicy.context.DeviceTokenResponseContext;
@@ -63,7 +66,6 @@ import jakarta.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.Map;
-import org.keycloak.protocol.oidc.grants.OAuth2GrantType;
/**
* OAuth 2.0 Device Authorization Grant
@@ -72,7 +74,7 @@ import org.keycloak.protocol.oidc.grants.OAuth2GrantType;
* @author Hiroyuki Wada
* @author Michito Okai
*/
-public class DeviceGrantType extends OAuth2GrantTypeBase {
+public class DeviceGrantType extends OAuth2GrantTypeBase implements EnvironmentDependentProviderFactory {
private static final String PROVIDER_ID = "device_code";
@@ -356,9 +358,14 @@ public class DeviceGrantType extends OAuth2GrantTypeBase {
return new DeviceGrantType();
}
+ @Override
+ public boolean isSupported() {
+ return Profile.isFeatureEnabled(Profile.Feature.DEVICE_FLOW);
+ }
+
@Override
public String getId() {
return PROVIDER_ID;
}
-}
\ No newline at end of file
+}