@Override
    public Service resolveServiceFrom(final Service service) {
        val clientId = resolveClientIdFromService(service);

        if (clientId.isPresent()) {
            service.getAttributes().computeIfAbsent(OAuth20Constants.CLIENT_ID,
                __ -> CollectionUtils.wrapList(clientId.get().getValue()));

            val redirectUri = resolveRedirectUri(service);
            if (redirectUri.isPresent()) {
                return createService(redirectUri.get().getValue(), service);
            }
            val grantType = resolveGrantType(service);
            if (grantType.isPresent()) {
                var id = StringUtils.EMPTY;
                val grantValue = grantType.get().getValue();
                if (OAuth20Utils.isGrantType(grantValue, OAuth20GrantTypes.CLIENT_CREDENTIALS)) {
                    LOGGER.debug("Located grant type [{}]; checking for service headers", grantValue);
                    val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
                    val response = HttpRequestUtils.getHttpServletResponseFromRequestAttributes();
                    id = OAuth20Utils.getServiceRequestHeaderIfAny(new JEEContext(request, response));
                }
                if (StringUtils.isBlank(id)) {
                    id = clientId.get().getValue();
                }
                LOGGER.debug("Built web application service based on identifier [{}]", id);
                return createService(id, service);
            }
        }
        return service;
    }
This is {@link OAuth20AuthenticationServiceSelectionStrategy}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-oauth-core-api/src/main/java/org/apereo/cas/support/oauth/services/OAuth20AuthenticationServiceSelectionStrategy.java