Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
@Data
public class ReissueRequest {
private String refreshToken;
private String accessToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import org.atdev.artrip.constants.Provider;

@AllArgsConstructor
@Data
public class SocialUserInfo {
private String email;
private String Nickname;
private String ProviderId;
private Provider provider;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.atdev.artrip.global.apipayload.code.status;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.atdev.artrip.global.apipayload.code.BaseErrorCode;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum AuthError implements BaseErrorCode {

// Auth Errors
_UNSUPPORTED_SOCIAL_PROVIDER(HttpStatus.BAD_REQUEST, "AUTH400-UNSUPPORTED_PROVIDER", "지원하지 않는 소셜 로그인입니다."),
_SOCIAL_EMAIL_NOT_PROVIDED(HttpStatus.BAD_REQUEST, "AUTH400-EMAIL_NOT_PROVIDED", "소셜 로그인에서 이메일 정보를 제공받지 못했습니다.");

private final HttpStatus httpStatus;
private final String code;
private final String message;

}
16 changes: 16 additions & 0 deletions src/main/java/org/atdev/artrip/jwt/JwtProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.security.Key;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;

@Slf4j
@Component
Expand Down Expand Up @@ -97,9 +98,24 @@ private Claims parseClaims(String accessToken) {
}
}

//만료까지 남은시간
public long getExpiration(String accessToken) {

try {
Claims claims = Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(accessToken)
.getBody();

long expirationTime = claims.getExpiration().getTime();
long now = new Date().getTime();

return (expirationTime - now);
} catch (ExpiredJwtException e){
return 0;

Choose a reason for hiding this comment

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

토큰이 만료되었다면 예외를 반환하는게 좋지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

해당 로직은 로그아웃시 엑세스토큰 만료까지 남은 기간을 구하는 로직입니다
엑세스토큰이 만료되었다면 사용 할 수 없는 상태로 관리할 필요가 없어 0을 반환하여 건너 뛸 수 있게 설계하였습니다

Choose a reason for hiding this comment

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

API에서 활용되는 부분이라면 예외가 맞을 것 같고 그게 아니라 단순 계산이라면 지금처럼 해도 될 것 같네요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 만료예외를 제외한 예외에는 에러처리를 하겠습니다

}
}
}


Loading