public ModelAndView encode(final AccessTokenRequestContext tokenRequestContext,
                               final OAuth20TokenGeneratedResult result) {
        LOGGER.debug("Generating access token response for [{}]", result);
        val deviceRefreshInterval = Beans.newDuration(getConfigurationContext().getCasProperties()
            .getAuthn().getOauth().getDeviceToken().getRefreshInterval()).toSeconds();
        val deviceTokenExpirationPolicy = getConfigurationContext().getDeviceTokenExpirationPolicy();
        val accessTokenTimeout = determineAccessTokenTimeoutInSeconds(result);

        val tokenResult = OAuth20AccessTokenResponseResult
            .builder()
            .registeredService(tokenRequestContext.getRegisteredService())
            .service(tokenRequestContext.getService())
            .accessTokenTimeout(accessTokenTimeout)
            .deviceRefreshInterval(deviceRefreshInterval)
            .deviceTokenTimeout(deviceTokenExpirationPolicy.buildTicketExpirationPolicyFor(
                tokenRequestContext.getRegisteredService()).getTimeToLive())
            .responseType(result.getResponseType().orElse(OAuth20ResponseTypes.NONE))
            .casProperties(getConfigurationContext().getCasProperties())
            .generatedToken(result)
            .grantType(result.getGrantType().orElse(OAuth20GrantTypes.NONE))
            .userProfile(tokenRequestContext.getUserProfile())
            .requestedTokenType(tokenRequestContext.getRequestedTokenType())
            .tokenExchangeAudience(tokenRequestContext.getTokenExchangeAudience())
            .tokenExchangeResource(tokenRequestContext.getTokenExchangeResource())
            .build();
        val generatedTokenResult = getConfigurationContext().getAccessTokenResponseGenerator().generate(tokenResult);
        val context = new LinkedHashMap<>(generatedTokenResult.getModel());
        if (generatedTokenResult.getStatus() != null) {
            context.put("status", generatedTokenResult.getStatus());
        }
        context.put(CasProtocolConstants.PARAMETER_SERVICE, tokenResult.getService().getId());
        Optional.ofNullable(tokenRequestContext.getToken()).ifPresent(token -> context.put(OAuth20Constants.TOKEN, token.getId()));
        context.put(OAuth20Constants.CLIENT_ID, tokenRequestContext.getRegisteredService().getClientId());
        context.put(OAuth20Constants.GRANT_TYPE, tokenRequestContext.getGrantType().getType());
        context.put(OAuth20Constants.RESPONSE_TYPE, tokenRequestContext.getResponseType().getType());
        LoggingUtils.protocolMessage("OAuth/OpenID Connect Token Response", context);
        configurationContext.getApplicationContext().publishEvent(
            new OAuth20AccessTokenResponseEvent(this, ClientInfoHolder.getClientInfo(), context));
        return generatedTokenResult;
    }
Encode access token into model and view.

@param tokenRequestContext the token request context
@param result              the result
@return the model and view
support/cas-server-support-oauth-core-api/src/main/java/org/apereo/cas/support/oauth/web/endpoints/OAuth20AccessTokenResponseEncoder.java