protected Ticket generateRefreshToken(final AccessTokenRequestContext tokenRequestContext,
                                          final String accessTokenId) throws Throwable {
        LOGGER.debug("Creating refresh token for [{}]", tokenRequestContext.getService());
        val refreshTokenFactory = (OAuth20RefreshTokenFactory) ticketFactory.get(OAuth20RefreshToken.class);
        val ticketGrantingTicket = tokenRequestContext.getTicketGrantingTicket() == null || tokenRequestContext.getTicketGrantingTicket().isExpired()
            ? null : tokenRequestContext.getTicketGrantingTicket();
        val scopes = tokenRequestContext.getGrantType() == OAuth20GrantTypes.REFRESH_TOKEN
            ? tokenRequestContext.getToken().getScopes() : tokenRequestContext.getScopes();
        val refreshToken = refreshTokenFactory.create(tokenRequestContext.getService(),
            tokenRequestContext.getAuthentication(),
            ticketGrantingTicket,
            scopes,
            tokenRequestContext.getRegisteredService().getClientId(),
            accessTokenId,
            tokenRequestContext.getClaims(),
            tokenRequestContext.getResponseType(),
            tokenRequestContext.getGrantType());
        
        if (refreshToken.getExpirationPolicy().getTimeToLive() > 0) {
            LOGGER.debug("Adding refresh token [{}] to the registry", refreshToken);
            val addedRefreshToken = addTicketToRegistry(refreshToken, ticketGrantingTicket);
            if (tokenRequestContext.isExpireOldRefreshToken()) {
                expireOldRefreshToken(tokenRequestContext);
            }
            return addedRefreshToken;
        }
        LOGGER.debug("Refresh token expiration policy for [{}] does not allow refresh tokens to be added to the registry",
            refreshToken.getId());
        return null;
    }
This is {@link OAuth20DefaultTokenGenerator}.

@author Misagh Moayyed
@since 5.2.0
support/cas-server-support-oauth-core-api/src/main/java/org/apereo/cas/support/oauth/web/response/accesstoken/OAuth20DefaultTokenGenerator.java