diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/dto/Logout.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/dto/Logout.kt deleted file mode 100644 index 8a9af1e3..00000000 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/dto/Logout.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.bamyanggang.apimodule.domain.user.application.dto - -class Logout { - - data class Request( - val refreshToken: String - ) - -} \ No newline at end of file diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/service/AuthService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/service/AuthService.kt index c69f62bf..b00a0d64 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/service/AuthService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/application/service/AuthService.kt @@ -1,6 +1,5 @@ package com.bamyanggang.apimodule.domain.user.application.service -import com.bamyanggang.apimodule.domain.user.application.dto.Logout import com.bamyanggang.apimodule.domain.user.application.dto.Reissue import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin import com.bamyanggang.apimodule.domain.user.application.service.handler.AuthHandler @@ -26,7 +25,8 @@ class AuthService( private val tokenAppender: TokenAppender, private val claimsExtractor: ClaimsExtractor, private val tokenRemover: TokenRemover, - private val tokenReader : TokenReader + private val tokenReader : TokenReader, + private val tokenExtractor: TokenExtractor ){ fun executeSocialLogin(provider: SocialLoginProvider, request: SocialLogin.Request): SocialLogin.Response { val socialLoginHandler = authHandlerManager.getHandler(provider) @@ -63,7 +63,8 @@ class AuthService( } @Transactional - fun logout(logoutRequest: Logout.Request) { - tokenReader.readToken(logoutRequest.refreshToken).also { tokenRemover.removeToken(it) } + fun logout(refreshToken: String) { + val refreshToken = tokenExtractor.extractValue(refreshToken) + tokenReader.readToken(refreshToken).also { tokenRemover.removeToken(it) } } } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthApi.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthApi.kt index 592babb6..0a8108be 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthApi.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthApi.kt @@ -7,4 +7,6 @@ object AuthApi { const val LOGOUT = "$BASE_URL/logout" const val REISSUE = "$BASE_URL/reissue" -} \ No newline at end of file + const val REFRESH_TOKEN_HEADER = "RefreshToken" + +} diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthController.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthController.kt index 5e5a6f70..21171d5a 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthController.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthController.kt @@ -1,16 +1,10 @@ package com.bamyanggang.apimodule.domain.user.presentation -import com.bamyanggang.apimodule.domain.user.application.dto.Logout import com.bamyanggang.apimodule.domain.user.application.dto.Reissue import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin import com.bamyanggang.apimodule.domain.user.application.service.AuthService import com.bamyanggang.domainmodule.domain.user.enums.SocialLoginProvider -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.PutMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RestController class AuthController( @@ -30,9 +24,9 @@ class AuthController( @DeleteMapping(AuthApi.LOGOUT) fun logout( - @RequestBody request: Logout.Request + @RequestHeader(AuthApi.REFRESH_TOKEN_HEADER) refreshTokenHeader: String ) { - authService.logout(request) + authService.logout(refreshTokenHeader) } -} \ No newline at end of file +} diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthControllerTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthControllerTest.kt index f35343cd..b5d017c7 100644 --- a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthControllerTest.kt +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/user/presentation/AuthControllerTest.kt @@ -1,7 +1,6 @@ package com.bamyanggang.apimodule.domain.user.presentation import com.bamyanggang.apimodule.BaseRestDocsTest -import com.bamyanggang.apimodule.domain.user.application.dto.Logout import com.bamyanggang.apimodule.domain.user.application.dto.Reissue import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin import com.bamyanggang.apimodule.domain.user.application.service.AuthService @@ -18,6 +17,8 @@ import org.springframework.restdocs.request.RequestDocumentation.parameterWithNa import org.springframework.restdocs.request.RequestDocumentation.pathParameters import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import com.bamyanggang.commonmodule.fixture.generateFixture +import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName +import org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders @WebMvcTest(AuthController::class) class AuthControllerTest : BaseRestDocsTest(){ @@ -125,19 +126,20 @@ class AuthControllerTest : BaseRestDocsTest(){ @DisplayName("로그아웃 요청시 성공한다.") fun logout() { //given - val refreshToken : String= generateFixture() - val logoutRequest = Reissue.Request(refreshToken) val request = RestDocumentationRequestBuilders.delete(AuthApi.LOGOUT) + .header("Authorization","Bearer accessToken") + .header("RefreshToken","Bearer refreshToken") .contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(logoutRequest)) + //when val result = mockMvc.perform(request) //then result.andExpect(status().isOk) .andDo( resultHandler.document( - requestFields( - fieldWithPath("refreshToken").description("로그아웃을 위한 refreshToken"), + requestHeaders( + headerWithName("Authorization").description("Access Token"), + headerWithName("RefreshToken").description("refreshToken") ) ) )