Skip to content

Commit

Permalink
feat: Oauth2.0 테스트 및 캐스팅 버그 수정
Browse files Browse the repository at this point in the history
- Get /jwt-test 테스트
- casting User to UserDetails 버그 수정
  • Loading branch information
minnseong committed May 30, 2023
1 parent 077407c commit 4af1cbf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ private void saveAuthentication(User user) {
password = PasswordUtil.generateRandomPassword();
}

UserDetails userDetails = (UserDetails) User.builder()
.email(user.getEmail())
UserDetails userDetails = org.springframework.security.core.userdetails.User.builder()
.username(user.getEmail())
.password(password)
.role(user.getRole())
.roles(user.getRole().name())
.build();

Authentication authentication =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
if (oAuth2User.getRole() == Role.GUEST) {
String accessToken = jwtService.createAccessToken(oAuth2User.getEmail());
response.addHeader(jwtService.getAccessHeader(), "Bearer " + accessToken);
response.sendRedirect("oauth2/sign-up");
// response.sendRedirect("oauth2/sign-up");

jwtService.sendAccessAndRefreshToken(response, accessToken, null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import devteamOne.classmate.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -24,4 +25,9 @@ public ResponseEntity<BasicResponse> signUp(@RequestBody UserSignUpDto userSignU
BasicResponse.from("S-00", "회원 가입 성공")
);
}

@GetMapping("/jwt-test")
public String jwtTest() {
return "jwtTest 요청 성공";
}
}

0 comments on commit 4af1cbf

Please sign in to comment.