-
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.
Merge pull request #44 from Kakaotech-18-Ecommerce/SCRUM-15-social-login
[Feat] JWT + social login(카카오,네이버)
- Loading branch information
Showing
18 changed files
with
643 additions
and
13 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/kakaoteck/golagola/Repository/UserRepository.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,11 @@ | ||
package com.kakaoteck.golagola.Repository; | ||
|
||
import com.kakaoteck.golagola.entity.UserEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<UserEntity, Long> { | ||
UserEntity findByUsername(String username); // username을 전달하여 해당하는 엔티티 가져오기(JPA) | ||
} | ||
|
||
|
||
|
17 changes: 17 additions & 0 deletions
17
src/main/java/com/kakaoteck/golagola/config/CorsMvcConfig.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,17 @@ | ||
package com.kakaoteck.golagola.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CorsMvcConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry corsRegistry) { | ||
|
||
corsRegistry.addMapping("/**") | ||
.exposedHeaders("Set-Cookie") | ||
.allowedOrigins("http://localhost:3000"); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kakaoteck/golagola/controller/MainController.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,16 @@ | ||
package com.kakaoteck.golagola.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
public class MainController { | ||
|
||
@GetMapping("/") | ||
@ResponseBody | ||
public String index(){ | ||
return "main route"; | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kakaoteck/golagola/controller/MyController.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,16 @@ | ||
package com.kakaoteck.golagola.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
public class MyController { | ||
|
||
@GetMapping("/my") | ||
@ResponseBody | ||
public String myApi(){ | ||
return "myApi"; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/kakaoteck/golagola/dto/CustomOAuth2User.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,49 @@ | ||
package com.kakaoteck.golagola.dto; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.oauth2.core.user.OAuth2User; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
public class CustomOAuth2User implements OAuth2User{ | ||
|
||
private final UserDTO userDTO; | ||
|
||
public CustomOAuth2User(UserDTO userDTO) { | ||
|
||
this.userDTO = userDTO; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAttributes() { | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { //Role값을 구현해주는 형태 | ||
|
||
Collection<GrantedAuthority> collection = new ArrayList<>(); | ||
collection.add(new GrantedAuthority() { | ||
|
||
@Override | ||
public String getAuthority() { | ||
|
||
return userDTO.getRole(); | ||
} | ||
}); | ||
return collection; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return userDTO.getName(); | ||
} | ||
|
||
public String getUsername() { | ||
return userDTO.getUsername(); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/kakaoteck/golagola/dto/KakaoResponse.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,40 @@ | ||
package com.kakaoteck.golagola.dto; | ||
|
||
import java.util.Map; | ||
|
||
public class KakaoResponse implements OAuth2Response{ | ||
|
||
private final Map<String, Object> attribute; | ||
|
||
public KakaoResponse(Map<String, Object> attribute) { | ||
this.attribute = attribute; | ||
} | ||
|
||
@Override | ||
public String getProvider() { | ||
return "kakao"; | ||
} | ||
|
||
@Override | ||
public String getProviderId() { | ||
return attribute.get("id").toString(); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
// "kakao_account" 필드에 포함된 "email" 값을 가져옵니다. | ||
Map<String, Object> kakaoAccount = (Map<String, Object>) attribute.get("kakao_account"); | ||
if (kakaoAccount != null) { | ||
return kakaoAccount.get("email").toString(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
// "kakao_account" 필드에 포함된 "name" 값을 가져옵니다. | ||
Map<String, Object> kakaoAccount = (Map<String, Object>) attribute.get("kakao_account"); | ||
Map<String, Object> profile = (Map<String, Object>) kakaoAccount.get("profile"); | ||
return profile.get("nickname").toString(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/kakaoteck/golagola/dto/NaverResponse.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,34 @@ | ||
package com.kakaoteck.golagola.dto; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
public class NaverResponse implements OAuth2Response{ | ||
|
||
private final Map<String, Object> attribute; | ||
|
||
public NaverResponse(Map<String, Object> attribute) { | ||
|
||
this.attribute = (Map<String, Object>) attribute.get("response"); | ||
} | ||
|
||
@Override | ||
public String getProvider() { | ||
return "naver"; | ||
} | ||
|
||
@Override | ||
public String getProviderId() { | ||
return attribute.get("id").toString(); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
return attribute.get("email").toString(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return attribute.get("name").toString(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/kakaoteck/golagola/dto/OAuth2Response.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.kakaoteck.golagola.dto; | ||
|
||
public interface OAuth2Response { | ||
|
||
//제공자 (Ex. naver, google, ...) | ||
String getProvider(); | ||
//제공자에서 발급해주는 아이디(번호) | ||
String getProviderId(); | ||
//이메일 | ||
String getEmail(); | ||
//사용자 실명 (설정한 이름) | ||
String getName(); | ||
|
||
} |
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,13 @@ | ||
package com.kakaoteck.golagola.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class UserDTO { | ||
|
||
private String role; | ||
private String name; | ||
private String username; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/kakaoteck/golagola/entity/UserEntity.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,26 @@ | ||
package com.kakaoteck.golagola.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
public class UserEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String username; | ||
private String name; | ||
private String email; | ||
private String role; | ||
|
||
|
||
|
||
} |
Oops, something went wrong.