@Override
    public Service buildService(final OAuthRegisteredService registeredService,
                                final WebContext context, final boolean useServiceHeader) {
        var serviceIdentifier = StringUtils.EMPTY;
        if (useServiceHeader) {
            serviceIdentifier = OAuth20Utils.getServiceRequestHeaderIfAny(context);
            LOGGER.debug("Located service based on request header is [{}]", serviceIdentifier);
        }
        if (StringUtils.isBlank(serviceIdentifier)) {
            serviceIdentifier = registeredService.getClientId();
        }
        val service = webApplicationServiceServiceFactory.createService(serviceIdentifier);
        service.getAttributes().put(OAuth20Constants.CLIENT_ID, List.of(registeredService.getClientId()));
        service.getAttributes().put(RegisteredService.class.getName(), List.of(registeredService.getId()));
        return service;
    }
This is {@link OAuth20DefaultCasAuthenticationBuilder}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-oauth-core-api/src/main/java/org/apereo/cas/support/oauth/authenticator/OAuth20DefaultCasAuthenticationBuilder.java