Use EnvironmentDependentProviderFactory for DeviceGrantType

This commit is contained in:
Dmitry Telegin 2024-01-20 01:41:49 +00:00 committed by Pedro Igor
parent 983680ce0e
commit cc9c8fe78a
2 changed files with 10 additions and 10 deletions

View file

@ -23,7 +23,6 @@ import org.keycloak.http.HttpResponse;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.OAuthErrorException; import org.keycloak.OAuthErrorException;
import org.keycloak.common.ClientConnection; import org.keycloak.common.ClientConnection;
import org.keycloak.common.Profile;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.models.AuthenticatedClientSessionModel; import org.keycloak.models.AuthenticatedClientSessionModel;
@ -219,12 +218,6 @@ public class TokenEndpoint {
grant = OAuth2GrantManager.resolve(session, grantType).orElseThrow(() -> newUnsupportedGrantTypeException()); grant = OAuth2GrantManager.resolve(session, grantType).orElseThrow(() -> newUnsupportedGrantTypeException());
event.event(grant.getEventType()); 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); event.detail(Details.GRANT_TYPE, grantType);
} }

View file

@ -21,6 +21,7 @@ import static org.keycloak.protocol.oidc.OIDCLoginProtocolService.tokenServiceBa
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.OAuthErrorException; import org.keycloak.OAuthErrorException;
import org.keycloak.common.Profile;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.Errors; import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
@ -37,11 +38,13 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleUseObjectProvider; import org.keycloak.models.SingleUseObjectProvider;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel; import org.keycloak.models.UserSessionModel;
import org.keycloak.provider.EnvironmentDependentProviderFactory;
import org.keycloak.protocol.LoginProtocol; import org.keycloak.protocol.LoginProtocol;
import org.keycloak.protocol.oidc.OIDCLoginProtocol; import org.keycloak.protocol.oidc.OIDCLoginProtocol;
import org.keycloak.protocol.oidc.OIDCLoginProtocolService; import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
import org.keycloak.protocol.oidc.TokenManager; import org.keycloak.protocol.oidc.TokenManager;
import org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint; 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.OAuth2GrantTypeBase;
import org.keycloak.protocol.oidc.grants.device.clientpolicy.context.DeviceTokenRequestContext; import org.keycloak.protocol.oidc.grants.device.clientpolicy.context.DeviceTokenRequestContext;
import org.keycloak.protocol.oidc.grants.device.clientpolicy.context.DeviceTokenResponseContext; 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.net.URI;
import java.util.Map; import java.util.Map;
import org.keycloak.protocol.oidc.grants.OAuth2GrantType;
/** /**
* OAuth 2.0 Device Authorization Grant * OAuth 2.0 Device Authorization Grant
@ -72,7 +74,7 @@ import org.keycloak.protocol.oidc.grants.OAuth2GrantType;
* @author <a href="mailto:h2-wada@nri.co.jp">Hiroyuki Wada</a> * @author <a href="mailto:h2-wada@nri.co.jp">Hiroyuki Wada</a>
* @author <a href="mailto:michito.okai.zn@hitachi.com">Michito Okai</a> * @author <a href="mailto:michito.okai.zn@hitachi.com">Michito Okai</a>
*/ */
public class DeviceGrantType extends OAuth2GrantTypeBase { public class DeviceGrantType extends OAuth2GrantTypeBase implements EnvironmentDependentProviderFactory {
private static final String PROVIDER_ID = "device_code"; private static final String PROVIDER_ID = "device_code";
@ -356,9 +358,14 @@ public class DeviceGrantType extends OAuth2GrantTypeBase {
return new DeviceGrantType(); return new DeviceGrantType();
} }
@Override
public boolean isSupported() {
return Profile.isFeatureEnabled(Profile.Feature.DEVICE_FLOW);
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
} }
} }