Skip to content

Commit

Permalink
refactor : 로그아웃 API 요청 형식 변경(#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed May 20, 2024
1 parent 02dea5f commit bf1fae3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ object AuthApi {
const val LOGOUT = "$BASE_URL/logout"
const val REISSUE = "$BASE_URL/reissue"

}
const val REFRESH_TOKEN_HEADER = "RefreshToken"

}
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
}

}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(){
Expand Down Expand Up @@ -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")
)
)
)
Expand Down

0 comments on commit bf1fae3

Please sign in to comment.