-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/#146/리프레쉬 토큰 도입 #156
The head ref may contain hidden characters: "feat/#146/\uB9AC\uD504\uB808\uC26C-\uD1A0\uD070-\uB3C4\uC785"
Feat/#146/리프레쉬 토큰 도입 #156
Changes from 26 commits
aeccc18
9f7c8e7
7e6e479
c6dec8c
3802066
d7bdf99
2f56cfd
b38cbd7
068ec55
b2b1aa2
e456315
565d4cd
c705e48
a704a7e
06b53d4
f5df44e
2c42a77
373b392
84de52a
5af7702
2c0bf76
8f4ae5c
4044089
432d54f
89a444c
d5329d8
8b96674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import space.space_spring.entity.TokenStorage; | ||
import space.space_spring.entity.User; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface JwtRepository extends JpaRepository<TokenStorage, Long> { | ||
|
||
Optional<TokenStorage> findByUser(User user); | ||
void deleteByUser(User user); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
import space.space_spring.entity.User; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
@Query("SELECT u FROM User u WHERE u.userId = :userId AND u.status = 'ACTIVE'") | ||
Optional<User> findByUserId(Long userId); | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package space.space_spring.dto.jwt; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class TokenPairDTO { | ||
|
||
private String refreshToken; | ||
private String accessToken; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package space.space_spring.dto.jwt; | ||
|
||
public enum TokenType { | ||
REFRESH, | ||
ACCESS | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package space.space_spring.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "Token_Storage") | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TokenStorage { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "token_storage_id") | ||
private Long tokenStorageId; | ||
|
||
@OneToOne | ||
// @Column(name = "user_id") | ||
private User user; | ||
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 안그래도 저희가 아직 redis 를 도입하지않아 token 같이 자주 변경되는 값을 저장할때의 성능에 대해 의문이 있었는데 첨부해주신 블로그 한번 참고해보겠습니다! |
||
|
||
@Column(name = "token_value") | ||
private String tokenValue; | ||
|
||
public void updateTokenValue(String tokenValue) { | ||
this.tokenValue = tokenValue; | ||
} | ||
|
||
public boolean checkTokenValue(String tokenValue) { | ||
return this.tokenValue.equals(tokenValue); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3 :
"/token"
도 괜찮은 것 같습니다. "자원"의 이름이기도 하고, "재"발급과 헷갈릴 요소도 있을것 같아서정답은 없는 것 같고 보통 어떻게 사용하는지 저는 모르지만 제안 드려봅니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 사실 requestBody 가 없어서 Post 메서드를 사용하는게 맞을지 고민을 했지만, Get 은 뭔가 조회의 역할이 강하다고 생각했고, token의 재발급(== 새로운 토큰의 발급 == 새로운 토큰의 생성)이 목적인 api 요청이라 Post 메서드를 사용했긴 합니다.
마찬가지로 재발급이라는 의미를 담아서 url을 new-token 이라 명명해보았습니다.
이건 어디까지나 저의 의견이었고, restful 한 url 을 위해 뭐가 더 적절할 지 조금 더 생각해보겠습니다!
의견 감사합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 "발급"도 일종의 "조회"(데이터를 가져오는 것)이라고 생각했는데,
GET
: 같은 요청을 여러번 해도 같은 결과를 내야함(멱등성)GET
: 데이터를 수정하는 것은 비권장POST
: 데이터를 생성하는가의 기준들로 보았을때,
POST
도 적절하다고 생각합니다./new-token
도 의미가 확실한 것 같네요아무래도 refresh token이 보안 도메인이기도 하고 다른 HTTP 통신들과 다른 흐름을 가지고 있어서 REST API에 딱 맞게 설계하기가 어렵네요