-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARV-120] OAuth2 로그인 리다이렉트 추가 (#106)
* [ARV-120] chore: application-dev gitignore 추가 * [ARV-120] fix: login시 리다이렉트 추가 * [ARV-120] refactor: member swagger 분리 * [ARV-120] feat: 회원 가입 및 회원정보 수정 시 이미지 저장 로직 추가 * [ARV-120] fix: oauth2 로그인 시 redirect 되도록 수정 및 refresh, access token을 cookie로 저장하도록 수정 * [ARV-120] fix: redirect 주석 해제 * [ARV-120] fix: main, concert, rent 일부 API permitAll
- Loading branch information
Showing
26 changed files
with
409 additions
and
172 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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/backend/allreva/auth/domain/RefreshToken.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,21 @@ | ||
package com.backend.allreva.auth.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@Getter | ||
@RedisHash(value = "refreshToken", timeToLive = 14440) | ||
public class RefreshToken { | ||
|
||
@Id | ||
private String token; | ||
private Long memberId; | ||
|
||
@Builder | ||
private RefreshToken(final String token, final Long memberId) { | ||
this.token = token; | ||
this.memberId = memberId; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/backend/allreva/auth/domain/RefreshTokenRepository.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,6 @@ | ||
package com.backend.allreva.auth.domain; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> { | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/backend/allreva/auth/util/CookieUtil.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,30 @@ | ||
package com.backend.allreva.auth.util; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseCookie; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class CookieUtil { | ||
|
||
private static final String COOKIE_DOMAIN = "localhost:3000"; | ||
|
||
// refreshToken 쿠키 생성 | ||
public static void addCookie( | ||
final HttpServletResponse response, | ||
final String name, | ||
final String value, | ||
final int maxAge | ||
) { | ||
ResponseCookie cookie = ResponseCookie.from(name, value) | ||
//.domain(COOKIE_DOMAIN) | ||
.path("/") | ||
.maxAge(maxAge) | ||
.httpOnly(true) | ||
.build(); | ||
|
||
response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/backend/allreva/common/config/RedisEmbeddedConfig.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,48 @@ | ||
package com.backend.allreva.common.config; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.annotation.PreDestroy; | ||
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.repository.configuration.EnableRedisRepositories; | ||
import redis.embedded.RedisServer; | ||
|
||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisEmbeddedConfig { | ||
|
||
private final RedisServer redisServer; | ||
|
||
public RedisEmbeddedConfig( | ||
@Value("${spring.data.redis.port}") final int port, | ||
@Value("${spring.data.redis.host}") final String host | ||
) { | ||
this.redisServer = new RedisServer(port); | ||
} | ||
|
||
@PostConstruct | ||
public void startRedis() { | ||
redisServer.start(); | ||
} | ||
|
||
@PreDestroy | ||
public void stopRedis() { | ||
redisServer.stop(); | ||
} | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory connectionFactory) { | ||
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(connectionFactory); | ||
return template; | ||
} | ||
} |
Oops, something went wrong.