Updated on 2025-11-13 GMT+08:00

Web Channel Interface Authentication

Implementation

To invoke a web interface, the cookie in the request must contain ccmessaging-token. During page integration, the CC-Messaging writes the value of ccmessaging-token to browser cookies through the request response. The token is verified as follows:

 /**
     * Check whether the token is valid.
     *
     * @param oldToken Token for agent or client access.
     * @return true indicates the token is valid and false indicates the token is invalid.
     */
    @Override
    public boolean isValid(String oldToken) throws Exception {
        boolean isValidResult = false;
        String cacheTokenValue = "";
        if (!ChatStringUtils.isEmpty(oldToken)) { // The input token must not be empty.
            String tokenCacheKey = null;
            try {
                String urlDecodeToken = URLDecoder.decode(oldToken, "UTF-8"); // The URL-encoded character string is obtained in the frontend.
                String baseDecodeToken = new String(Base64.getDecoder().decode(urlDecodeToken), "UTF-8");
                JSONObject userInfoObject = JSON.parseObject(baseDecodeToken);
                String uid = String.valueOf(userInfoObject.get("tenantId")) + String.valueOf(
                    userInfoObject.get("channelId")) + String.valueOf(userInfoObject.get("userId"));
                tokenCacheKey = cacheService.getChatCacheKey("TOKENKEY", uid);
                cacheTokenValue = BaseUtil.decode(cacheService.getValue(tokenCacheKey));
            } catch (Exception e) {
                RedisCacheUtil.putRedisCache(Boolean.FALSE, e);
                if (tokenCacheKey != null) {
                    cacheTokenValue = BaseUtil.decode(cacheService.getValue(tokenCacheKey));
                }
                log.error("Invalid AccessToken!Please check!", e);
            }
            if (!ChatStringUtils.isEmpty(cacheTokenValue) && cacheTokenValue.equals(
                oldToken)) { // Check whether the input token is the same as the token obtained by the Redis.
                isValidResult = true;
            }
        }
        return isValidResult;
    }