protected AccessAndRefreshTokens generateAccessTokenOAuthGrantTypes(
        final AccessTokenRequestContext tokenRequestContext) throws Throwable {
        LOGGER.debug("Creating access token for [{}]", tokenRequestContext.getService());

        if (tokenRequestContext.getGrantType() == OAuth20GrantTypes.TOKEN_EXCHANGE) {
            return generateAccessTokenForTokenExchange(tokenRequestContext);
        }

        val authentication = finalizeAuthentication(tokenRequestContext, prepareAuthentication(tokenRequestContext));
        LOGGER.debug("Creating access token for [{}]", tokenRequestContext);
        val accessToken = createAccessToken(tokenRequestContext, authentication);
        val addedAccessToken = addAccessToken(tokenRequestContext, accessToken);
        val refreshToken = FunctionUtils.doIf(tokenRequestContext.isGenerateRefreshToken(),
            Unchecked.supplier(() -> generateRefreshToken(tokenRequestContext, accessToken.getId())),
            () -> {
                LOGGER.debug("Service [{}] is not able/allowed to receive refresh tokens", tokenRequestContext.getService());
                return null;
            }).get();
        return new AccessAndRefreshTokens(addedAccessToken, refreshToken);
    }
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