-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. gateway oauth2login + oauth2ResourceServer + MapReactiveUserDetailService implemented. from spring 3.2.x, need to implement MapReactiveUserDetailService by my own. ref: spring-projects/spring-boot#37504 (comment)
- Loading branch information
Showing
15 changed files
with
209 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...end/java/backend/gateway/src/main/java/com/example/gateway/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//package com.example.gateway.controller; | ||
// | ||
//import com.example.gateway.dto.AuthResponse; | ||
//import com.google.api.client.auth.oauth2.TokenRequest; | ||
//import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; | ||
//import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; | ||
//import com.google.api.client.http.javanet.NetHttpTransport; | ||
//import com.google.api.client.json.jackson.JacksonFactory; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.beans.factory.annotation.Value; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.web.bind.annotation.PostMapping; | ||
//import org.springframework.web.bind.annotation.RequestBody; | ||
//import org.springframework.web.bind.annotation.RestController; | ||
// | ||
//import java.util.Collections; | ||
// | ||
//@RestController | ||
//@Slf4j | ||
//public class AuthController { | ||
// @Value("${spring.security.oauth2.client.registration.google.client-id}") | ||
// private String clientId; | ||
// | ||
// @PostMapping("/api/auth/google") | ||
// public ResponseEntity<?> authenticateGoogle(@RequestBody TokenRequest tokenRequest) { | ||
// try { | ||
// log.info("authenticate Google tokenRequest: {}", tokenRequest); | ||
// GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), new JacksonFactory()) | ||
// .setAudience(Collections.singletonList(clientId)) | ||
// .build(); | ||
// | ||
// GoogleIdToken idToken = verifier.verify(tokenRequest.toString()); | ||
// if (idToken != null) { | ||
// GoogleIdToken.Payload payload = idToken.getPayload(); | ||
// | ||
// String userId = payload.getSubject(); | ||
// String email = payload.getEmail(); | ||
// boolean emailVerified = Boolean.valueOf(payload.getEmailVerified()); | ||
// String name = (String) payload.get("name"); | ||
// String pictureUrl = (String) payload.get("picture"); | ||
// | ||
// // 여기서 사용자 정보를 데이터베이스에 저장하거나 업데이트할 수 있습니다. | ||
// // 그리고 자체 JWT 토큰을 생성하여 반환할 수 있습니다. | ||
// return ResponseEntity.ok(new AuthResponse(userId, email, name)); | ||
// } else { | ||
// return ResponseEntity.badRequest().body("Invalid ID token."); | ||
// } | ||
// } catch (Exception e) { | ||
// return ResponseEntity.badRequest().body("Token verification failed: " + e.getMessage()); | ||
// } | ||
// } | ||
// | ||
// | ||
//} |
14 changes: 14 additions & 0 deletions
14
backend/java/backend/gateway/src/main/java/com/example/gateway/dto/AuthResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.gateway.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
public class AuthResponse { | ||
private String userId; | ||
private String email; | ||
private String name; | ||
|
||
// constructor, getters and setters | ||
} |
43 changes: 43 additions & 0 deletions
43
...ava/backend/gateway/src/main/java/com/example/gateway/service/CustomOAuthUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//package com.example.gateway.service; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; | ||
//import org.springframework.stereotype.Service; | ||
// | ||
//@Slf4j | ||
//@Service | ||
//@RequiredArgsConstructor | ||
//public class CustomOAuthUserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> { | ||
// private final SocialMemberRepository socialMemberRepository; | ||
// | ||
// @Override | ||
// public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { | ||
// OAuth2UserService delegate = new DefaultOAuth2UserService(); | ||
// OAuth2User oAuth2User = delegate.loadUser(userRequest); | ||
// log.info("oauth2user = {}",oAuth2User); | ||
// String email = oAuth2User.getAttribute("email"); | ||
// String nickname = UUID.randomUUID().toString().substring(0,15); | ||
// String password = "default"; | ||
//// Role role = Role.ROLE_USER; | ||
// | ||
// | ||
// Optional<SocialMember> socialMember = socialMemberRepository.findByEmail(email); | ||
// | ||
// List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); | ||
// | ||
// if(socialMember.isEmpty()){ | ||
// SocialMember savedSocialMember = SocialMember.createSocialMember(email, nickname); | ||
// SaveMemberResponseDto savedResponse = socialMemberRepository.save(savedSocialMember); | ||
// authorities.add(new SimpleGrantedAuthority("ROLE_FIRST_JOIN")); | ||
// User savedUser = new User (String.valueOf(savedResponse.getId()),password,authorities); | ||
// return new CustomUserDetails(String.valueOf(savedResponse.getId()),authorities,savedUser,oAuth2User.getAttributes()); | ||
// } | ||
// else{ | ||
// authorities.add(new SimpleGrantedAuthority("ROLE_EXIST_USER")); | ||
// User savedUser = new User (String.valueOf(socialMember.get().getUserId()),password,authorities); | ||
// return new CustomUserDetails(savedUser.getUsername(),authorities,savedUser,oAuth2User.getAttributes()); | ||
// } | ||
// } | ||
// | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters