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

[FIX] 유저 권한 획득 로직 변경 #169

Open
JuneParkCode opened this issue Sep 1, 2024 · 0 comments
Open

[FIX] 유저 권한 획득 로직 변경 #169

JuneParkCode opened this issue Sep 1, 2024 · 0 comments
Assignees
Labels
⌨️ BE Backend 작업 🛠️ fix 버그 수정

Comments

@JuneParkCode
Copy link
Contributor

수정 전 기능

  • 유저 생성 이후 권한 획득 시 항상 USER 권한으로 획득
  • ADMIN 또한 똑같은 USER로 할당 받아 권한 제어의 문제가 발생

수정 후 기능

	@Override
	public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
		OAuth2UserInfo oAuth2User = new NaverOAuth2User(super.loadUser(userRequest).getAttributes());
		Map<String, Object> attributes = oAuth2User.getAttributes();
		Email email = new Email((String)attributes.get("email"));
		UserEntity user = userRepository.findByEmail(email).orElse(null);
		attributes.put("accessToken", userRequest.getAccessToken().getTokenValue());
		if (user == null) {
			return oAuth2User;
		}
		attributes.put("userId", user.getId());
		attributes.put("nickname", user.getNickname());
		return new NaverOAuth2User(attributes,
			List.of(new SimpleGrantedAuthority(AuthRole.USER.getName())));
	}

수정 의도

  • 버그 수정

TODO

CustomOAuth2Service.java 수정

@JuneParkCode JuneParkCode added ⌨️ BE Backend 작업 🛠️ fix 버그 수정 labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ BE Backend 작업 🛠️ fix 버그 수정
Projects
None yet
Development

No branches or pull requests

3 participants