JWT 만료 및 검증 규칙
exp, nbf, iat와 같은 시간 기반 클레임으로 JWT 수명이 제어되는 방식과 검증기가 만료되었거나 아직 유효하지 않은 토큰을 거부하는 방식을 이해해 보세요.
JWT 만료 및 검증 규칙은(는) CoddyKit의 무료 Spring Security 6 & JWT Authentication 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Spring Security 6 & JWT Authentication 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Spring Security 6 & JWT Authentication 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Tokens Need a Lifetime
A JWT is a bearer credential: whoever holds it is trusted. If a token never expired, a leaked token would grant access forever.
Time-based claims limit the damage window by making tokens valid only for a short period.
The exp Claim
The exp (expiration) claim is a Unix timestamp. After this moment the token is invalid and must be rejected.
{
'sub': 'user123',
'exp': 1717200000
}The iat Claim
The iat (issued at) claim records when the token was created. It is useful for measuring token age and for revoking all tokens issued before a certain time.
{
'sub': 'user123',
'iat': 1717196400,
'exp': 1717200000
}The nbf Claim
The nbf (not before) claim defines the earliest time a token becomes valid. A token used before its nbf time must be rejected, which is handy for tokens scheduled to activate later.
{
'sub': 'user123',
'nbf': 1717196400,
'exp': 1717200000
}Choosing an Expiration Window
Short lifetimes are safer but force frequent re-authentication. A common pattern is:
- Access token: 5-15 minutes
- Refresh token: days or weeks
The short access token limits exposure; the refresh token keeps the user logged in.
Setting exp When Issuing
When you build a token, set exp relative to now. Here a 15-minute access token is created using a JWT library.
const now = Math.floor(Date.now() / 1000);
const payload = {
sub: 'user123',
iat: now,
exp: now + 15 * 60
};Validating exp on the Server
On every request the server checks exp against the current time. Most libraries do this automatically and throw if the token is expired.
try {
const claims = verify(token, secret);
} catch (err) {
if (err.name === 'TokenExpiredError') {
// reject with 401
}
}Clock Skew
Servers do not always have perfectly synchronized clocks. A small leeway (a few seconds) prevents valid tokens from being rejected because of minor clock differences.
verify(token, secret, { clockTolerance: 5 });exp Is Not Encryption
Remember: a JWT payload is only encoded, not encrypted. The exp claim stops the server from accepting the token, but anyone can read the claims. Never put secrets in the payload.
Reacting to Expiry on the Client
When the client gets a 401 due to expiry, it should silently request a new access token using the refresh token, then retry the original request.
if (response.status === 401) {
const fresh = await refreshAccessToken();
return retryWith(fresh);
}Common Validation Mistakes
Watch out for these errors:
- Forgetting to validate exp at all
- Using milliseconds instead of seconds for the timestamp
- Setting an excessively long lifetime
- Ignoring nbf, allowing premature use
Quick Check
Test your knowledge of JWT time claims.
Recap
You learned how JWT lifetime is controlled:
expsets the expiration;iatrecords issue time;nbfsets earliest validity- Use short access tokens plus longer refresh tokens
- Allow small clock skew with leeway
- exp does not encrypt the payload
Proper expiration handling keeps stolen tokens useful for only a brief window.
자주 묻는 질문
“JWT 만료 및 검증 규칙” 강의는 무료인가요?
네 — “JWT 만료 및 검증 규칙” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Spring Security 6 & JWT Authentication 강의 전체를 잠금 해제할 수 있습니다. Spring Security 6 & JWT Authentication 강의에는 총 4개의 강의가 포함되어 있습니다.
“JWT 만료 및 검증 규칙”에서 뭘 배우나요?
exp, nbf, iat와 같은 시간 기반 클레임으로 JWT 수명이 제어되는 방식과 검증기가 만료되었거나 아직 유효하지 않은 토큰을 거부하는 방식을 이해해 보세요. 브라우저에서 직접 실행하는 실습 코드로 Spring Security 6 & JWT Authentication을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Spring Security 6 & JWT Authentication을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Spring Security 6 & JWT Authentication은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“JWT 만료 및 검증 규칙” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Spring Security 6 & JWT Authentication 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Spring Security 6 & JWT Authentication 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- JSON 웹 토큰 이해하기
- JWT 구조 및 클레임
- JWT 서명 및 검증
- JWT 만료 및 검증 규칙