Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update jwt api #77

Merged
merged 6 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/docs/asciidoc/api/Authorization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
:toclevels: 2
:seclinks:

=== 엑세스 토큰 재발급
=== 액세스 토큰 재발급

Access Token이 만료된 경우 ``Refresh Token``을 이용하여 ``새로운 Access Token``을 발급받을 수 있습니다.
주의할 점은 `만료된 Access Token` 또한 헤더에 포함시켜 보내야 한다는 것입니다.
액세스 토큰이 만료된 경우 ``리프레시 토큰``을 이용하여 ``액세스 토큰``을 재발급 받을 수 있습니다.

operation::jwt/refresh[snippets='http-request,http-response,response-fields']
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,45 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.test.web.servlet.ResultActions;

@WebMvcTest(JwtController.class)
class JwtControllerTest extends AbstractRestDocsTests {

static final String ACCESS_TOKEN_PREFIX = "Bearer ";
static final String REFRESH_TOKEN_NAME = "refresh";

@MockBean
JwtTokenProvider jwtTokenProvider;

@MockBean
JwtService jwtService;

@Test
@DisplayName("access token 갱신 성공 시 새로 발급한 token을 전달한다.")
@DisplayName("Access Token 재발급")
void refresh() throws Exception {

// given
given(jwtService.refreshToken(
any(HttpServletRequest.class), any(HttpServletResponse.class), eq("accessToken")
)).willReturn("newAccessToken");
any(HttpServletRequest.class), any(HttpServletResponse.class), eq("OLD_ACCESS_TOKEN")
)).willReturn("NEW_ACCESS_TOKEN");

// when
ResultActions result = mockMvc.perform(post("/api/v1/jwt/refresh")
.cookie(new Cookie(REFRESH_TOKEN_NAME, "OLD_REFRESH_TOKEN"))
.header(HttpHeaders.AUTHORIZATION, ACCESS_TOKEN_PREFIX + "OLD_ACCESS_TOKEN"));

mockMvc.perform(post("/api/v1/jwt/refresh")
.cookie(new Cookie("refresh", "refreshToken"))
.header("Authorization", "Bearer " + "accessToken"))
.andExpect(status().isOk())
// then
result.andExpect(status().isOk())
.andDo(document("jwt/refresh",
requestCookies(
cookieWithName("refresh").description("refresh token")
),
requestHeaders(
headerWithName("Authorization").description("access token")
),
requestCookies(cookieWithName(REFRESH_TOKEN_NAME).description("재발급할 리프레시 토큰")),
requestHeaders(headerWithName(HttpHeaders.AUTHORIZATION).description("재발급할 액세스 토큰")),
responseFields(
fieldWithPath("status").description("응답 상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("data").description("응답 데이터"),
fieldWithPath("data.accessToken").description("새로 발급한 access token")
fieldWithPath("data.accessToken").description("재발급한 액세스 토큰")
)
));
}
Expand Down