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

[bug] 로그아웃 문제 #29

Closed
yonghwankim-dev opened this issue Nov 24, 2023 · 0 comments · Fixed by #30
Closed

[bug] 로그아웃 문제 #29

yonghwankim-dev opened this issue Nov 24, 2023 · 0 comments · Fixed by #30
Assignees
Labels
bug Something isn't working

Comments

@yonghwankim-dev
Copy link
Member

yonghwankim-dev commented Nov 24, 2023

상황

소셜 로그인은 잘 수행되지만 로그아웃이 수행되지 않습니다.

원인

컨트롤러 매핑 메소드에 accessToken을 전달하지 않고 있습니다.

image

기존에는 LogoutInterceptor에 의해서 컨트롤러 전달전에 Authorization 헤더에서 accessToken을 파싱하여 RequestAttribute로 설정하였지만 security 라이브러리 도입 과정에서 설정이 빠진 것을 확인하였습니다.

해결방법

LogoutInterceptor를 설정에 추가합니다.

@Slf4j
public class LogoutInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
		Exception {
		log.debug("로그아웃 인터셉터 접속 : {}", request.getRequestURI());
		String accessToken = extractJwt(request).orElseThrow(
			() -> new UnAuthorizationException(JwtErrorCode.EMPTY_TOKEN));
		request.setAttribute("accessToken", accessToken);
		return true;
	}

	private Optional<String> extractJwt(HttpServletRequest request) {
		String header = request.getHeader(AUTHORIZATION);

		if (!StringUtils.hasText(header) || !header.startsWith(BEARER)) {
			return Optional.empty();
		}

		return Optional.of(header.split(" ")[1]);
	}
}
@yonghwankim-dev yonghwankim-dev added the bug Something isn't working label Nov 24, 2023
@yonghwankim-dev yonghwankim-dev self-assigned this Nov 24, 2023
yonghwankim-dev added a commit that referenced this issue Nov 24, 2023
- 로그아웃 인터셉터를 추가하여 컨트롤러 매핑 메소드 전달전에 Authorization 헤더에서 accessToken을 추출하여 RequestAttribute에 저장하도록 처리합니다.
yonghwankim-dev added a commit that referenced this issue Nov 24, 2023
- 로그아웃 인터셉터를 추가하여 컨트롤러 매핑 메소드 전달전에 Authorization 헤더에서 accessToken을 추출하여 RequestAttribute에 저장하도록 처리합니다.
@yonghwankim-dev yonghwankim-dev linked a pull request Nov 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant