-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from alzzaipo/refresh-token
리프레시 토큰 도입
- Loading branch information
Showing
24 changed files
with
437 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.alzzaipo.common.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate() { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
|
||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
|
||
return redisTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.alzzaipo.common.jwt; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class TokenInfo { | ||
|
||
private final String accessToken; | ||
private final String RefreshToken; | ||
|
||
public TokenInfo(String accessToken, String refreshToken) { | ||
this.accessToken = accessToken; | ||
RefreshToken = refreshToken; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/alzzaipo/member/adapter/in/web/LoginController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.alzzaipo.member.adapter.in.web; | ||
|
||
import com.alzzaipo.common.jwt.TokenInfo; | ||
import com.alzzaipo.member.adapter.in.web.dto.LocalLoginWebRequest; | ||
import com.alzzaipo.member.adapter.in.web.dto.RefreshTokenDto; | ||
import com.alzzaipo.member.adapter.in.web.dto.TokenResponse; | ||
import com.alzzaipo.member.application.port.in.RefreshTokenUseCase; | ||
import com.alzzaipo.member.application.port.in.account.local.LocalLoginUseCase; | ||
import com.alzzaipo.member.application.port.in.dto.AuthorizationCode; | ||
import com.alzzaipo.member.application.port.in.dto.LocalLoginCommand; | ||
import com.alzzaipo.member.application.port.in.dto.LoginResult; | ||
import com.alzzaipo.member.application.port.in.oauth.KakaoLoginUseCase; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/login") | ||
@RequiredArgsConstructor | ||
public class LoginController { | ||
|
||
private final LocalLoginUseCase localLoginUseCase; | ||
private final KakaoLoginUseCase kakaoLoginUseCase; | ||
private final RefreshTokenUseCase refreshTokenUseCase; | ||
|
||
@PostMapping("/local") | ||
public ResponseEntity<TokenResponse> login(@Valid @RequestBody LocalLoginWebRequest dto) { | ||
LocalLoginCommand localLoginCommand = new LocalLoginCommand( | ||
dto.getAccountId(), | ||
dto.getAccountPassword()); | ||
|
||
LoginResult loginResult = localLoginUseCase.handleLocalLogin(localLoginCommand); | ||
|
||
if (loginResult.isSuccess()) { | ||
TokenResponse tokenResponse = TokenResponse.build(loginResult.getTokenInfo()); | ||
return ResponseEntity.ok(tokenResponse); | ||
} | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); | ||
} | ||
|
||
@GetMapping("/kakao") | ||
public ResponseEntity<TokenResponse> kakaoLogin(@RequestParam("code") String authCode) { | ||
AuthorizationCode authorizationCode = new AuthorizationCode(authCode); | ||
|
||
LoginResult loginResult = kakaoLoginUseCase.handleLogin(authorizationCode); | ||
|
||
if (loginResult.isSuccess()) { | ||
TokenResponse tokenResponse = TokenResponse.build(loginResult.getTokenInfo()); | ||
return ResponseEntity.ok(tokenResponse); | ||
} | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
|
||
@PostMapping("/refresh-token") | ||
public ResponseEntity<TokenResponse> refreshToken(@Valid @RequestBody RefreshTokenDto dto) { | ||
TokenInfo tokenInfo = refreshTokenUseCase.refresh(dto.getRefreshToken()); | ||
TokenResponse tokenResponse = TokenResponse.build(tokenInfo); | ||
return ResponseEntity.ok(tokenResponse); | ||
} | ||
} |
Oops, something went wrong.