- Last Updated
Web Service Session Optimization
Understanding
Session integration optimization is a feature that caches recent verification results to avoid repeating the validation of the SUAT (Security User Access Token) for every request or action. Upon the initial entry, the SUAT is verified via the Accounts authentication API (/auth/v5/user_token/check), and the result is stored in the cache. For subsequent requests from the same user, the authentication API call is skipped if the cache is valid. This allows you to maintain the latest authentication status while minimizing authentication API calls.
The integration method is divided into two types depending on the rendering environment. The SSR environment (backend), where pages are rendered on the server, uses server-side Redis as the verification cache, while the CSR/SPA environment (frontend), where screens are rendered in the browser, uses Session Storage as the verification cache.
Applicable Environments
The verification API and purpose are the same; only the cache storage and key differ. You can choose the track that fits your service's rendering method.
| Category | SSR (Backend) | CSR (Frontend) |
|---|---|---|
| Rendering Location | Page rendering on server | Screen rendering in browser |
| Typical Environment | Spring-based SSR service | SPA (Client-side Routing) service |
| Verification Cache Storage | Redis | Session Storage |
| Cache Key | Secure key based on SUAT (e.g., SUAT_CHECK:{SUAT_HASH}) |
STOVE_USER_TOKEN_CHECK |
| Cache TTL | 300 seconds (5 minutes) | 300 seconds (5 minutes) |
| Verification API | /auth/v5/user_token/check |
/auth/v5/user_token/check |
Components
| Component | Role |
|---|---|
| Client (Browser) | SUAT cookie delivery (SSR), token verification request based on user actions (CSR) |
| SSR Service (BE) | Extract SUAT from request, determine whether to call Auth API by checking Redis verification cache, page rendering |
| SPA Service (FE) | Determine whether to call Auth API by checking Session Storage verification cache, perform common verification before API call |
| Auth API | /auth/v5/user_token/checkfor SUAT validity verification |
| Redis (SSR) | Server-side cache that stores recently verified SUAT results for a TTL duration |
| Session Storage (CSR) | Browser-side cache that stores verification time and expiration time |
Operating Principle
Upon initial entry, the SUAT is verified via the Auth API and the result is stored in the cache. For subsequent requests with the same SUAT/session, if the cache is valid (within 5 minutes), the Auth API call is skipped; re-verification occurs only if the cache is missing, expired, or the SUAT has changed. This reduces redundant verification calls for the same SUAT, improving response performance.
SSR stores verification results in server-side Redis, allowing multiple requests and multiple servers to share the cache. CSR stores them in the browser's Session Storage, which persists through refreshes (F5) but is deleted when the tab is closed. Regardless of the method, it is recommended to use hash values such as SHA-256 rather than using the raw SUAT as the cache key directly.
Integration Guide
Prerequisites
These are the common requirements for both SSR and CSR. Detailed preparations for each method are provided in their respective [Development] tracks.
| Item | Description | Note |
|---|---|---|
| SUAT Authentication Token | accounts.onstove.com/loginSUAT authentication token issuance completed on Client |
Required |
| Auth Verification API Integration | /auth/v5/user_token/checkSecure a path to verify SUAT validity by calling the API |
Required |
| Verification Cache Storage | Configure Redis for SSR and Session Storage for CSR | Required |
| Cache Key/TTL Policy | Apply a secure key to identify SUAT and a TTL of 300 seconds (5 minutes). Skip verification if cache exists; re-verify if missing or expired | Required |
Consult with the Publishing Tech team regarding API access permissions
Please confirm API access permissions and environment-specific domains with the person in charge. Inquiry: sgp_publishtech_d@smilegate.com
Basic Verification Flow
When a request or action occurs, the SUAT is extracted to check the verification cache; if the cache is valid, the Auth API call is skipped. The Auth API is called and the result is stored in the cache only when the cache is missing, expired, or the SUAT has changed. Both SSR and CSR follow the decision flow below.
Items to Decide Before Starting
Decide on the following items before service integration. The cache structure and authentication failure handling method will vary depending on the results.
| Decision Items | Content |
|---|---|
| Cache Key Structure | Secure key format to identify SUAT (Redis Key for SSR, Session Storage Key for CSR) |
| Cache TTL | Reuse time for verification results (default 300 seconds) |
| Authentication API Call Method | Call method (GET/POST, etc.) and SUAT delivery method |
| Authentication Success/Failure Criteria | Criteria for determining success/failure based on HTTP Status or business codes |
| Authentication Failure Policy | Distinction between expiration, tampering, and non-authentication, and follow-up processing methods |
| Cache Sharing Method (SSR) | Whether to use a shared Redis across multiple servers |
| Login Redirect Policy | Processing method for Redirect or 401 response upon authentication failure |
Environment Classification Guide
The applicable environment varies depending on the service's rendering method and the availability of cache storage.
| Classification | Applicable Environment |
|---|---|
| SSR Applicable | Spring-based SSR services, environments where Redis is available, environments where SUAT Cookie can be retrieved from the server, and environments where Accounts authentication API can be called |
| CSR Applicable | SPA (Client-side Routing) services, environments where Session Storage is available, POST /auth/v5/user_token/check environments where calls are possible |
| Separate Review Required | SSR environments where Redis cannot be used, environments where neither server nor browser cache can be used |
Integration Checklist
Check the items below before integration.
| Checklist | Content |
|---|---|
| SUAT Cookie | Check Name, Domain, and Path |
| Authentication API | Check URL and HTTP Method |
| Authentication Request Method | Check Cookie delivery method |
| Success Response | Check HTTP Status and business code |
| Failure Response | Check distinction between expiration, tampering, and unauthenticated |
| Redis (SSR) | Check Key structure and TTL, and whether a shared Redis for multiple servers is used |
| Session Storage (CSR) | Check key and TTL, and whether common validation logic is applied |
| Login Processing | Check Redirect or 401 policy |
| Network | Check Authentication API access permissions |
| Operational Monitoring | Monitor Authentication API call volume and failure rate |
Development
SSR Integration (Backend)
This is for integration in environments where pages are rendered on the server. The server extracts the SUAT included in the request, decides whether to call the Authentication API based on the Redis validation cache, and if the cache is valid, renders the page without re-validating.
Prerequisites
accounts.onstove.com/loginmust have a SUAT authentication token issued to the Client.- The SSR service must be able to receive the SUAT Cookie included in the request header.
/auth/v5/user_token/checkAPI must be integrated to verify SUAT validity.- A Redis cache must be configured to store validation results, using a secure key to identify the SUAT and a TTL of 300 seconds (5 minutes).
- Implement logic to skip the authentication validation API call if the Redis cache exists, and only re-validate if it is missing or expired.
Development Flow
Perform user authentication using the SUAT held by the Client upon entering the SSR service. Cache the validation result in Redis to reduce repeated validation calls for the same SUAT.
- Extract SUAT from the request header when entering the SSR service.
- Query the Redis validation cache using a SUAT-based cache key (e.g.,
SUAT_CHECK:{SUAT_HASH}). - If the cache exists and is valid, process the request without calling
/auth/v5/user_token/check. - If the cache is missing or expired, call
/auth/v5/user_token/checkto verify the SUAT. - If validation is successful, store the result in Redis and set the TTL to 300 seconds (5 minutes).
- Subsequent requests with the same SUAT will reuse the cache, improving SSR service response performance.
Do not use the raw SUAT as a Redis key directly
Redis is an authentication validation cache used to reuse SUAT validation results for a certain period. It is recommended to use a hash value such as SHA-256 instead of using the raw SUAT as the key directly.
Troubleshooting
These are the handling methods for each response code. Please refer to the API & SDK Reference menu for detailed response code and message specifications.
| HTTP Status | Business Code | Message | Description |
|---|---|---|---|
| 200 | 0 | success | Success |
| 400 | 400 | bad request | Bad Request |
| 500 | 500 | unknown error | Internal Server Error |
Sample Code
This is an example of comparing the requested SUAT with the cached SUAT in a Spring-based SSR service and calling the Authentication API only when the value changes. In a multi-server environment, please use a shared Redis as a cache instead of a local session to share validation results across servers.
java import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import org.springframework.http.*; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.client.RestTemplate; import java.util.Arrays; import java.util.Objects;
@Controller public class MainController {
private static final String AUTH_API = "https://accounts.onstove.com/auth/v5/user_token/check";
private final RestTemplate restTemplate = new RestTemplate();
@GetMapping("/main") public String main(HttpServletRequest request) { HttpSession session = request.getSession(); // Validation cache expiration time 5 minutes (300 seconds) session.setMaxInactiveInterval(300);
// 1. Extract SUAT from request Cookie String requestSuat = Arrays.stream(request.getCookies()) .filter(cookie -> "SUAT".equals(cookie.getName())) .map(Cookie::getValue) .findFirst() .orElse(null);
// 2. Query SUAT stored in cache String sessionSuat = (String) session.getAttribute("SUAT");
// 3. Call authentication API if SUAT has changed or cache is missing
if (!Objects.equals(requestSuat, sessionSuat)) {
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.COOKIE, "SUAT=" + requestSuat);
HttpEntity
CSR Integration (Frontend)
This is for integration in an SPA environment where the browser renders the screen. The decision to call the authentication API is determined by the Session Storage verification cache; if the cache is valid, the request is processed without re-verification.
Prerequisites
accounts.onstove.com/loginmust be used to issue a SUAT authentication token.- The SPA service must be able to verify the validity of the user token via the
POST /auth/v5/user_token/checkAPI. - You must be able to use Session Storage to store verification results.
- The verification cache is stored in Session Storage using the
STOVE_USER_TOKEN_CHECKkey and managed with a TTL of 300 seconds (5 minutes). - It is recommended to handle all API calls through common logic (Interceptor or API Wrapper) that checks the verification cache.
Development Flow
Check the verification cache in Session Storage upon initial service entry and for every user action. If the cache is valid, the authentication API call is skipped, and the cache is maintained even after a refresh (F5).
- Upon initial service entry, verify the user token validity via
POST /auth/v5/user_token/check. - Once verified, store the verification time (verifiedAt) and expiration time (expireAt) in Session Storage(
STOVE_USER_TOKEN_CHECK). - Before calling an API due to a user action, check the verification cache in Session Storage.
- If the cache is valid (within 5 minutes), skip the authentication API call and process the request.
- If the cache has expired or is missing, call the authentication API again to verify, then update the Session Storage.
- Since Session Storage is maintained even when the browser is refreshed (F5), no re-verification is performed if the cache is valid.
Session Storage cache is maintained on refresh but deleted when the tab is closedSTOVE_USER_TOKEN_CHECK stores the verification time (verifiedAt) and expiration time (expireAt). It is valid for 5 minutes from verifiedAt, and re-verification is required after expireAt. It is maintained even on refresh (F5) but is deleted when the browser (tab) is closed.
Troubleshooting
These are the handling methods for each response code. Please refer to the API & SDK Reference menu for detailed response code and message specifications.
| HTTP Status | Business Code | Message | Description |
|---|---|---|---|
| 200 | 0 | success | Success |
| 400 | 400 | bad request | Bad request |
| 500 | 500 | unknown error | Internal server error |
Sample Code
This is an example of checking the Session Storage verification cache to skip the authentication API call if valid, and performing token verification via a common wrapper before API calls.
const STORAGE_KEY = "STOVE_USER_TOKEN_CHECK";
const CACHE_TTL = 5 * 60 * 1000; // 5분
/**
* 토큰 유효성 검증. 캐시가 유효하면 API 호출을 생략해요.
*/
async function validateUserToken() {
const cache = getTokenCheckCache();
// 캐시가 유효하면 검증 API 호출 생략
if (cache && cache.expireAt > Date.now()) {
console.log("Skip /auth/v5/user_token/check");
return true;
}
// 캐시가 없거나 만료 시 검증 API 호출
const response = await fetch("/auth/v5/user_token/check", {
method: "POST",
credentials: "include"
});
if (!response.ok) {
throw new Error("Invalid User Token");
}
saveTokenCheckCache();
return true;
}
/**
* 검증 결과를 Session Storage에 저장
*/
function saveTokenCheckCache() {
const now = Date.now();
sessionStorage.setItem(
STORAGE_KEY,
JSON.stringify({
verifiedAt: now,
expireAt: now + CACHE_TTL
})
);
}
/**
* Session Storage에서 검증 캐시 조회
*/
function getTokenCheckCache() {
const value = sessionStorage.getItem(STORAGE_KEY);
if (!value) {
return null;
}
try {
return JSON.parse(value);
} catch {
sessionStorage.removeItem(STORAGE_KEY);
return null;
}
}
/**
* API 호출 전 토큰 검증을 수행하는 공통 래퍼
*/
async function requestApi() {
await validateUserToken();
return fetch("/api/example", {
credentials: "include"
});
}