Skip to content

Commit b4daa7a

Browse files
authored
Merge pull request #29 from Decodeat/feat/28-logout
feat: 로그아웃
2 parents 8bbb58e + 23ace95 commit b4daa7a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/com/DecodEat/domain/refreshToken/service/TokenService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.DecodEat.domain.RefreshToken.service;
1+
package com.DecodEat.domain.refreshToken.service;
22

33

44
import static com.DecodEat.global.apiPayload.code.status.ErrorStatus.*;
@@ -10,14 +10,15 @@
1010
import lombok.RequiredArgsConstructor;
1111
import org.springframework.stereotype.Service;
1212

13+
1314
import java.time.Duration;
1415

1516
@RequiredArgsConstructor
1617
@Service
1718
public class TokenService {
1819

1920
private final JwtTokenProvider jwtTokenProvider;
20-
private final RefreshTokenService refreshTokenService;
21+
private final com.DecodEat.domain.RefreshToken.service.RefreshTokenService refreshTokenService;
2122
private final UserService userService;
2223

2324
public String createNewAccessToken(String refreshToken){

src/main/java/com/DecodEat/global/config/WebOAuthSecurityConfig.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
import com.DecodEat.global.config.oauth.OAuth2SuccessHandler;
88
import com.DecodEat.global.config.oauth.OAuth2UserCustomService;
99
import lombok.RequiredArgsConstructor;
10-
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
1110
import org.springframework.context.annotation.Bean;
1211
import org.springframework.context.annotation.Configuration;
1312
import org.springframework.http.HttpStatus;
1413
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
15-
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
1614
import org.springframework.security.config.http.SessionCreationPolicy;
1715
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
18-
import org.springframework.security.oauth2.client.TokenExchangeOAuth2AuthorizedClientProvider;
1916
import org.springframework.security.web.SecurityFilterChain;
2017
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
2118
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
2219
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
2320
import org.springframework.web.cors.CorsConfigurationSource;
21+
import org.springframework.beans.factory.annotation.Value;
2422

2523
@RequiredArgsConstructor
2624
@Configuration
@@ -31,6 +29,8 @@ public class WebOAuthSecurityConfig {
3129
private final RefreshTokenRepository refreshTokenRepository;
3230
private final UserService userService;
3331
private final CorsConfigurationSource corsConfigurationSource; // CorsCongifuragtinoSource Bean 주입 위함
32+
@Value("${spring.security.oauth2.client.registration.kakao.client-id}")
33+
private String kakaoClientId;
3434

3535
// @Bean
3636
// public WebSecurityCustomizer configure() {
@@ -77,6 +77,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
7777
.defaultAuthenticationEntryPointFor(
7878
new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
7979
new AntPathRequestMatcher("/api/**")));
80+
// 7. 로그아웃
81+
http.logout(logout -> logout
82+
.logoutUrl("/api/logout")
83+
// 👇 카카오 로그아웃 URL로 리다이렉트
84+
.logoutSuccessUrl("https://kauth.kakao.com/oauth/logout?client_id=" + kakaoClientId + "&logout_redirect_uri=https://decodeat.store.app/")
85+
.invalidateHttpSession(true)
86+
.deleteCookies("JSESSIONID")
87+
.clearAuthentication(true)
88+
);
8089

8190
return http.build();
8291
}

0 commit comments

Comments
 (0)