Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
912856d
fix: import๋ฌธ ๋ˆ„๋ฝ์œผ๋กœ ์ธํ•œ ์—๋Ÿฌ ํ•ด๊ฒฐ
byunhm02 May 18, 2026
52ea35c
chore: ํŒŒ์ผ ์œ„์น˜ ๋ณ€๊ฒฝ ๋ฐ ๋กœ๊ทธ ์ถ”๊ฐ€
byunhm02 May 19, 2026
efef28a
chore: ํŒจํ‚ค์ง€ ๋ณ€๊ฒฝ
byunhm02 May 19, 2026
d89ea6c
feat: ๋กœ๊ทธ์ธ, ํšŒ์›๊ฐ€์ž… ๊ด€๋ จ dto ์ƒ์„ฑ
byunhm02 May 20, 2026
dfa734a
feat:auth ์„ฑ๊ณต ๋ฐ ์—๋Ÿฌ ์ฝ”๋“œ ์ •์˜
byunhm02 May 20, 2026
cce58a4
feat: ํšŒ์›๊ฐ€์ž…,๋กœ๊ทธ์œˆ ์œ„ํ•œ ๋ณ€๊ฒฝ ๋ฐ ๋กœ๊ทธ์ธ ํƒ€์ž… ์ •์˜
byunhm02 May 20, 2026
320744a
refactor: ํŒจํ‚ค์ง€ ์œ„์น˜ ์ด๋™
byunhm02 May 21, 2026
e369bf3
feat: post, like์— ์ ‘๊ทผ ๊ถŒํ•œ ์„ค์ • ์ถ”๊ฐ€
byunhm02 May 21, 2026
333fe70
feat:jwtํ† ํฐ ๊ฒ€์ฆ ๋กœ์ง ์ถ”๊ฐ€
byunhm02 May 22, 2026
5384001
feat: ์ผ๋ฐ˜/์นด์นด์˜ค ๋กœ๊ทธ์ธ ๋ฐ ๋กœ๊ทธ์•„์›ƒ ๋กœ์ง ๊ตฌํ˜„
byunhm02 May 22, 2026
15180d2
feat: RedisConfig๊ตฌํ˜„
byunhm02 May 22, 2026
3f3ab82
feat: ์ธ์ฆ, ์ธ๊ฐ€ ๊ด€๋ จ utilํŒจํ‚ค์ง€ ์ƒ์„ฑ
byunhm02 May 22, 2026
9d51553
feat: ๋กœ๊ทธ์ธ ์—๋Ÿฌ์ฝ”๋“œ ๋ฐ ์ปจํŠธ๋กค๋Ÿฌ ๊ตฌํ˜„
byunhm02 May 22, 2026
40bcc26
feat: passwordencoder ์ถ”๊ฐ€
byunhm02 May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-security'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'

// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring-boot-starter-security๊ฐ€ 8๋ฒˆ์งธ ์ค„๊ณผ 16๋ฒˆ์งธ ์ค„์— ์ค‘๋ณต์œผ๋กœ ์„ ์–ธ๋˜์–ด ์žˆ์–ด์š”!! ๋‘˜ ์ค‘ ํ•˜๋‚˜ ์ œ๊ฑฐํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!


// WebClient (์นด์นด์˜ค API ํ˜ธ์ถœ์šฉ)
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

}
7 changes: 6 additions & 1 deletion src/main/java/org/sopt/auth/code/AuthSuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

@Getter
public enum AuthSuccessCode implements ResponseCode {
LOGIN_SUCCESS(HttpStatus.OK,"๋กœ๊ทธ์ธ ์„ฑ๊ณต!"),
KAKAO_LOGIN_SUCCESS(HttpStatus.OK,"์นด์นด์˜ค ๋กœ๊ทธ์ธ ์„ฑ๊ณต!"),
SIGNUP_SUCCESS(HttpStatus.OK,"ํšŒ์›๊ฐ€์ž… ์„ฑ๊ณต!"),
TOKEN_GENERATED(HttpStatus.CREATED, "ํ† ํฐ ๋ฐœ๊ธ‰ ์™„๋ฃŒ!"),
USER_SEARCHED(HttpStatus.OK,"์œ ์ € ์กฐํšŒ ์™„๋ฃŒ!");
USER_SEARCHED(HttpStatus.OK,"์œ ์ € ์กฐํšŒ ์™„๋ฃŒ!"),
LOGOUT_SUCCESS(HttpStatus.OK,"๋กœ๊ทธ์•„์›ƒ ์„ฑ๊ณต!")
;

private final HttpStatus status;
private final String message;
Expand Down
90 changes: 74 additions & 16 deletions src/main/java/org/sopt/auth/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,103 @@
package org.sopt.auth.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.sopt.auth.code.AuthSuccessCode;
import org.sopt.auth.dto.request.SignUpRequest;
import org.sopt.auth.service.AuthService;
import org.sopt.auth.dto.TokenResponse;
import org.sopt.auth.util.AccessTokenResolver;
import org.sopt.auth.util.CookieUtil;
import org.sopt.auth.util.HeaderUtil;
import org.sopt.global.api.response.BaseResponse;
import org.sopt.user.dto.UserResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.sopt.auth.dto.request.LoginRequest;
import org.sopt.auth.dto.request.KakaoLoginRequest;


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/auth")
@RequestMapping("/auth")
public class AuthController {

private final AuthService authService;

@Operation(summary = "ํšŒ์›๊ฐ€์ž… (Access Token + Refresh Token ๋ฐœ๊ธ‰)")
@PostMapping("/signup")
public ResponseEntity<BaseResponse<Void>> signup(
@RequestBody @Valid final SignUpRequest request,
HttpServletResponse response
) {
TokenResponse tokens = authService.signUp(request);
setTokens(response, tokens);
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.SIGNUP_SUCCESS));
}


@Operation(summary = "๋กœ๊ทธ์ธ (Access Token + Refresh Token ๋ฐœ๊ธ‰)")
@PostMapping("/login")
public ResponseEntity<BaseResponse<TokenResponse>> login(
@RequestParam("email") String email,
@RequestParam("password") String password
public ResponseEntity<BaseResponse<Void>> login(
@RequestBody @Valid final LoginRequest request,
HttpServletResponse response
) {
TokenResponse tokens = authService.login(email, password);
//todo: ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ ์ฟ ํ‚ค๋กœ ๋‹ด์•„์„œ ๋ณด๋‚ด๋„๋ก helper metohd private์œผ๋กœ ํ•˜๊ธฐ !!
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.TOKEN_GENERATED,tokens));
TokenResponse tokens = authService.login(request);
setTokens(response, tokens);
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.LOGIN_SUCCESS));
}

@Operation(summary = "๋‚ด ์ •๋ณด ์กฐํšŒ (Access Token ๊ฒ€์ฆ)")
@GetMapping("/api/v1/me")
public ResponseEntity<BaseResponse<UserResponse>> me(Authentication authentication) {
@Operation(summary = "์นด์นด์˜ค ๋กœ๊ทธ์ธ (์ธ๊ฐ€์ฝ”๋“œ๋กœ ํ† ํฐ ๋ฐœ๊ธ‰)")
@PostMapping("/kakao")
public ResponseEntity<BaseResponse<Void>> kakaoLogin(
@RequestBody @Valid final KakaoLoginRequest request,
HttpServletResponse response
) {
TokenResponse tokens = authService.kakaoLogin(request.code());
setTokens(response, tokens);
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.KAKAO_LOGIN_SUCCESS));
}

if (authentication == null || authentication.getPrincipal() == null) {
throw new IllegalArgumentException("์ธ์ฆ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}
@Operation(summary = "ํ† ํฐ ์žฌ๋ฐœ๊ธ‰")
@PostMapping("/reissue")
public ResponseEntity<BaseResponse<Void>> reissue(
HttpServletRequest request,
HttpServletResponse response
) {
String refreshToken = CookieUtil.getRefreshToken(request);
TokenResponse tokens = authService.reissue(refreshToken);
setTokens(response, tokens);
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.TOKEN_GENERATED));
}

Long memberId = Long.parseLong(authentication.getName());
@Operation(summary = "๋‚ด ์ •๋ณด ์กฐํšŒ (Access Token ๊ฒ€์ฆ)")
@GetMapping("/me")
public ResponseEntity<BaseResponse<UserResponse>> me(
@AuthenticationPrincipal Long memberId
) {
UserResponse member = authService.getMemberById(memberId);

return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.USER_SEARCHED,member));
}

@Operation(summary = "๋กœ๊ทธ์•„์›ƒ")
@PostMapping("/logout")
public ResponseEntity<BaseResponse<Void>> logout(
@AuthenticationPrincipal Long memberId,
HttpServletRequest request,
HttpServletResponse response
) {
String accessToken = AccessTokenResolver.resolve(request);
authService.logout(memberId,accessToken);
CookieUtil.deleteCookie(response, "refreshToken");
return ResponseEntity.ok(BaseResponse.success(AuthSuccessCode.LOGOUT_SUCCESS));
}

private void setTokens(HttpServletResponse response, TokenResponse tokens) {
HeaderUtil.setAuthorizationHeader(response, tokens.accessToken());
CookieUtil.addRefreshTokenCookie(response, tokens.refreshToken());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฟ ํ‚ค ๊ด€๋ จ ์„ธํŒ… ํ•จ์ˆ˜๋“ค์„ util ํด๋ž˜์Šค๋กœ ๋นผ์„œ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง„ ๊ฑฐ ๊ฐ™์•„์„œ ๋ฆฌ๋ทฐ์–ด ์ž…์žฅ์—์„œ ์ฝ๊ธฐ๊ฐ€ ์ข‹๋„ค์š”๐Ÿ‘

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.auth.dto.request;

public record KakaoLoginRequest(
String code
) {}
7 changes: 7 additions & 0 deletions src/main/java/org/sopt/auth/dto/request/LoginRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.auth.dto.request;

public record LoginRequest(
String email,
String password
) {
}
7 changes: 7 additions & 0 deletions src/main/java/org/sopt/auth/dto/request/SignUpRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.auth.dto.request;

public record SignUpRequest(
String nickname,
String email,
String password
) {}
32 changes: 32 additions & 0 deletions src/main/java/org/sopt/auth/exception/code/AuthErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.sopt.auth.exception.code;

import org.sopt.global.api.code.ResponseCode;
import org.springframework.http.HttpStatus;

public enum AuthErrorCode implements ResponseCode {
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ž…๋‹ˆ๋‹ค."),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "์œ ์ €๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
KAKAO_USER_CANNOT_LOGIN(HttpStatus.BAD_REQUEST, "์นด์นด์˜ค๋กœ ๊ฐ€์ž…ํ•œ ์œ ์ €์ž…๋‹ˆ๋‹ค. ์นด์นด์˜ค ๋กœ๊ทธ์ธ์„ ์ด์šฉํ•ด์ฃผ์„ธ์š”."),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "์ธ์ฆ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."),
EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT, "์ด๋ฏธ ์กด์žฌํ•˜๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค."),
SIGNUP_REQUIRED(HttpStatus.NOT_FOUND,"ํšŒ์›๊ฐ€์ž…์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."),
INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),

EMPTY_TOKEN(HttpStatus.UNAUTHORIZED, "ํ† ํฐ์ด ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค."),
MALFORMED_TOKEN(HttpStatus.UNAUTHORIZED, "ํ† ํฐ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, "ํ† ํฐ์ด ๋งŒ๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");

private final HttpStatus status;
private final String message;

AuthErrorCode(HttpStatus status, String message) {
this.status = status;
this.message = message;
}

@Override
public HttpStatus getStatus() { return status; }

@Override
public String getMessage() { return message; }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.sopt.global.api.jwt;
package org.sopt.auth.jwt;

import com.auth0.jwt.exceptions.JWTVerificationException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.sopt.auth.service.JwtService;
import org.sopt.auth.service.BlacklistService;
import org.sopt.global.api.exception.BaseException;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -22,6 +22,7 @@
public class JwtAuthFilter extends OncePerRequestFilter {

private final JwtService jwtService;
private final BlacklistService blacklistService;

@Override
protected void doFilterInternal(
Expand All @@ -30,20 +31,26 @@ protected void doFilterInternal(
FilterChain filterChain
) throws ServletException, IOException {
String header = request.getHeader(HttpHeaders.AUTHORIZATION);
System.out.println(">>> Header: " + header);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋กœ๊น…ํ•  ๋•Œ @Slf4j ์Šคํ”„๋ง ์ž์ฒด์—์„œ ์ œ๊ณตํ•˜๋Š” ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๊ฑธ ์ถ”์ฒœ๋“œ๋ ค์š”!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ ๊ฐ™์€ ์ƒ๊ฐ์ด์—์š”!! @slf4j + log.debug()๋กœ ๊ต์ฒดํ•˜๊ฑฐ๋‚˜, ๋””๋ฒ„๊น…์šฉ์ด์—ˆ๋‹ค๋ฉด ์ œ๊ฑฐํ•˜๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!


if (header != null && header.startsWith("Bearer ")) {
String token = header.substring("Bearer ".length()).trim();
try {
if (blacklistService.isBlacklisted(token)) {
filterChain.doFilter(request, response);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋กœ๊ทธ์•„์›ƒ๋œ Access Token์„ JwtAuthFilter ๋‹จ๊ณ„์—์„œ ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ๋กœ ํ™•์ธํ•˜๋„๋ก ํ•œ ์ ์ด ์ข‹์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! JWT๋Š” ๋งŒ๋ฃŒ ์ „๊นŒ์ง€ ์œ ํšจํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ๋กœ๊ทธ์•„์›ƒ๋œ ํ† ํฐ์„ ์ถ”๊ฐ€๋กœ ๊ฒ€์ฆํ•˜๋Š” ํ๋ฆ„์ด ๋ณด์•ˆ ์ธก๋ฉด์—์„œ ์ข‹๋‹ค๊ณ  ๋А๊ผˆ์Šต๋‹ˆ๋‹ค.๐Ÿ‘๐Ÿ‘

๊ทผ๋ฐ ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ์— ํ•ด๋‹นํ•˜๋Š” ๊ฒฝ์šฐ ์ง€๊ธˆ ์ฝ”๋“œ์—์„œ๋Š” filterChain์œผ๋กœ ๋„˜๊ธฐ๋Š” ๊ตฌ์กฐ๋กœ ๋ณด์—ฌ์„œ ๋กœ๊ทธ์•„์›ƒ๋œ ํ† ํฐ์ด๋ผ๋Š” ์ƒํ™ฉ์ด ์‘๋‹ต์—์„œ ๋ช…ํ™•ํžˆ ๋“œ๋Ÿฌ๋‚˜๋Š”์ง€ ํ•œ ๋ฒˆ ํ™•์ธํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

return;
}
Long memberId = jwtService.verifyAndGetMemberId(token);
System.out.println(">>> ์ธ์ฆ ์„ฑ๊ณต, memberId: " + memberId);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
String.valueOf(memberId), null, Collections.emptyList());
memberId, null, Collections.emptyList());
auth.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(auth);
} catch (IllegalArgumentException | JWTVerificationException e) {
// ์œ ํšจํ•˜์ง€ ์•Š์€ ํ† ํฐ ๋˜๋Š” ํ† ํฐ์ด ์—†๋Š” ๊ฒฝ์šฐ, ์ธ์ฆ ์—†์ด ๋‹ค์Œ ํ•„ํ„ฐ๋กœ ๋„˜๊ฒจ์š”.
// ์—ฌ๊ธฐ์„œ ์˜ˆ์™ธ๋ฅผ ๋˜์ง€์ง€ ์•Š๋Š” ์ด์œ ๋Š”, /v1/login ๊ฐ™์ด ์ธ์ฆ์ด ํ•„์š” ์—†๋Š” API๋„
// ์ด ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜๊ธฐ ๋•Œ๋ฌธ์ด์—์š”. ์ธ์ฆ ์—ฌ๋ถ€ ํŒ๋‹จ์€ SecurityConfig์˜
// authorizeHttpRequests ์„ค์ •์—์„œ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.
} catch (BaseException e) {
System.out.println(">>> ํ† ํฐ ๊ฒ€์ฆ ์‹คํŒจ: " + e.getMessage());
}
} else {
System.out.println(">>> Authorization ํ—ค๋” ์—†์Œ ๋˜๋Š” Bearer ํ˜•์‹ ์•„๋‹˜");
}

filterChain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.sopt.auth.service;
package org.sopt.auth.jwt;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.sopt.auth.exception.code.AuthErrorCode;
import org.sopt.global.api.exception.BaseException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -46,14 +50,32 @@ public String generateRefreshToken(Long memberId) {
}

public Long verifyAndGetMemberId(String token) {

if (token == null || token.isBlank()) {
throw new IllegalArgumentException("ํ† ํฐ์ด ์—†์Šต๋‹ˆ๋‹ค.");
throw new BaseException(AuthErrorCode.EMPTY_TOKEN);
}
DecodedJWT jwt = JWT.require(algorithm).build().verify(token);

try {
DecodedJWT jwt = JWT.require(algorithm).build().verify(token);
return Long.parseLong(jwt.getSubject());
} catch (TokenExpiredException e) {
throw new BaseException(AuthErrorCode.EXPIRED_TOKEN);
} catch (JWTVerificationException e) {
throw new BaseException(AuthErrorCode.MALFORMED_TOKEN);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("JWT์˜ ํšŒ์› ์ •๋ณด๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
throw new BaseException(AuthErrorCode.MALFORMED_TOKEN);
}
}

public long getRemainingMillis(String token) {
try {
DecodedJWT jwt = JWT.require(algorithm).build().verify(token);
Date expiration = jwt.getExpiresAt();
return expiration.getTime() - System.currentTimeMillis();
} catch (TokenExpiredException e) {
return 0;
} catch (JWTVerificationException e) {
throw new BaseException(AuthErrorCode.MALFORMED_TOKEN);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/sopt/auth/jwt/exception/EmptyTokenException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.auth.jwt.exception;

import org.sopt.auth.exception.code.AuthErrorCode;
import org.sopt.global.api.exception.BaseException;

public class EmptyTokenException extends BaseException {
public EmptyTokenException() {
super(AuthErrorCode.EMPTY_TOKEN);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.auth.jwt.exception;

import org.sopt.auth.exception.code.AuthErrorCode;
import org.sopt.global.api.exception.BaseException;

public class MalformedTokenException extends BaseException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—๋Ÿฌ์ฝ”๋“œ ๋ณ„๋กœ Exception ํด๋ž˜์Šค๋ฅผ ๋”ฐ๋กœ ๋งŒ๋“ค๋ฉด ํ™•์‹คํžˆ ์—๋Ÿฌ ์ถ”์ ์— ์šฉ์ดํ•  ๊ฒƒ ๊ฐ™๋„ค์š”!
๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค~

public MalformedTokenException() {
super(AuthErrorCode.MALFORMED_TOKEN);
}
}
Loading