-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 카카오 로그인 구현
- Loading branch information
Showing
24 changed files
with
540 additions
and
6 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
72 changes: 72 additions & 0 deletions
72
user-service/src/main/java/kr/mafoo/user/config/JacksonSerializer.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,72 @@ | ||
package kr.mafoo.user.config; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import io.jsonwebtoken.io.AbstractSerializer; | ||
import io.jsonwebtoken.lang.Assert; | ||
|
||
import java.io.OutputStream; | ||
|
||
public class JacksonSerializer<T> extends AbstractSerializer<T> { | ||
|
||
static final String MODULE_ID = "jjwt-jackson"; | ||
static final Module MODULE; | ||
|
||
static { | ||
SimpleModule module = new SimpleModule(MODULE_ID); | ||
// module.addSerializer(JacksonSupplierSerializer.INSTANCE); | ||
MODULE = module; | ||
} | ||
|
||
static final ObjectMapper DEFAULT_OBJECT_MAPPER = newObjectMapper(); | ||
|
||
/** | ||
* Creates and returns a new ObjectMapper with the {@code jjwt-jackson} module registered and | ||
* {@code JsonParser.Feature.STRICT_DUPLICATE_DETECTION} enabled (set to true) and | ||
* {@code DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES} disabled (set to false). | ||
* | ||
* @return a new ObjectMapper with the {@code jjwt-jackson} module registered and | ||
* {@code JsonParser.Feature.STRICT_DUPLICATE_DETECTION} enabled (set to true) and | ||
* {@code DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES} disabled (set to false). | ||
* | ||
* @since 0.12.4 | ||
*/ | ||
// package protected on purpose, do not expose to the public API | ||
static ObjectMapper newObjectMapper() { | ||
return new ObjectMapper() | ||
.registerModule(MODULE) | ||
.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true) // https://github.com/jwtk/jjwt/issues/877 | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // https://github.com/jwtk/jjwt/issues/893 | ||
} | ||
|
||
protected final ObjectMapper objectMapper; | ||
|
||
/** | ||
* Constructor using JJWT's default {@link ObjectMapper} singleton for serialization. | ||
*/ | ||
public JacksonSerializer() { | ||
this(DEFAULT_OBJECT_MAPPER); | ||
} | ||
|
||
/** | ||
* Creates a new Jackson Serializer that uses the specified {@link ObjectMapper} for serialization. | ||
* | ||
* @param objectMapper the ObjectMapper to use for serialization. | ||
*/ | ||
public JacksonSerializer(ObjectMapper objectMapper) { | ||
Assert.notNull(objectMapper, "ObjectMapper cannot be null."); | ||
this.objectMapper = objectMapper.registerModule(MODULE); | ||
} | ||
|
||
@Override | ||
protected void doSerialize(T t, OutputStream out) throws Exception { | ||
Assert.notNull(out, "OutputStream cannot be null."); | ||
ObjectWriter writer = this.objectMapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); | ||
writer.writeValue(out, t); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
user-service/src/main/java/kr/mafoo/user/config/properties/KakaoOAuthProperties.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,13 @@ | ||
package kr.mafoo.user.config.properties; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; | ||
|
||
@ConfigurationProperties(prefix = "app.oauth.kakao") | ||
@ConfigurationPropertiesBinding | ||
public record KakaoOAuthProperties( | ||
String clientId, | ||
String redirectUri, | ||
String clientSecret | ||
) { | ||
} |
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
8 changes: 8 additions & 0 deletions
8
user-service/src/main/java/kr/mafoo/user/controller/dto/response/KakaoLoginInfo.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,8 @@ | ||
package kr.mafoo.user.controller.dto.response; | ||
|
||
public record KakaoLoginInfo( | ||
String id, | ||
String nickname, | ||
String email | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
user-service/src/main/java/kr/mafoo/user/domain/AuthToken.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,8 @@ | ||
package kr.mafoo.user.domain; | ||
|
||
public record AuthToken( | ||
String accessToken, | ||
String refreshToken | ||
){ | ||
|
||
} |
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
65 changes: 65 additions & 0 deletions
65
user-service/src/main/java/kr/mafoo/user/domain/SocialMemberEntity.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,65 @@ | ||
package kr.mafoo.user.domain; | ||
|
||
import kr.mafoo.user.enums.IdentityProvider; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.Transient; | ||
import org.springframework.data.domain.Persistable; | ||
import org.springframework.data.relational.core.mapping.Column; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@Table("social_member") | ||
public class SocialMemberEntity implements Persistable<SocialMemberEntityKey> { | ||
@Column("identity_provider") | ||
private IdentityProvider identityProvider; | ||
|
||
@Column("identifier") | ||
private String id; | ||
|
||
@CreatedDate | ||
@Column("created_at") | ||
private LocalDateTime createdAt; | ||
|
||
@Column("member_id") | ||
private String memberId; | ||
|
||
@Transient | ||
private boolean isNew = false; | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
|
||
SocialMemberEntity that = (SocialMemberEntity) obj; | ||
|
||
return id.equals(that.id) && identityProvider.equals(that.identityProvider); | ||
} | ||
|
||
public SocialMemberEntityKey getId() { | ||
return new SocialMemberEntityKey(identityProvider, id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, identityProvider); | ||
} | ||
|
||
public static SocialMemberEntity newSocialMember(IdentityProvider identityProvider, String id, String memberId) { | ||
SocialMemberEntity socialMember = new SocialMemberEntity(); | ||
socialMember.identityProvider = identityProvider; | ||
socialMember.id = id; | ||
socialMember.memberId = memberId; | ||
socialMember.isNew = true; | ||
return socialMember; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
user-service/src/main/java/kr/mafoo/user/domain/SocialMemberEntityKey.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 kr.mafoo.user.domain; | ||
|
||
import kr.mafoo.user.enums.IdentityProvider; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
|
||
@RequiredArgsConstructor | ||
@Data | ||
public class SocialMemberEntityKey implements Serializable { | ||
private final IdentityProvider identityProvider; | ||
private final String id; | ||
} |
5 changes: 5 additions & 0 deletions
5
user-service/src/main/java/kr/mafoo/user/enums/IdentityProvider.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,5 @@ | ||
package kr.mafoo.user.enums; | ||
|
||
public enum IdentityProvider { | ||
KAKAO | ||
} |
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
7 changes: 7 additions & 0 deletions
7
user-service/src/main/java/kr/mafoo/user/exception/InvalidTokenException.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,7 @@ | ||
package kr.mafoo.user.exception; | ||
|
||
public class InvalidTokenException extends DomainException { | ||
public InvalidTokenException() { | ||
super(ErrorCode.TOKEN_INVALID); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
user-service/src/main/java/kr/mafoo/user/exception/KakaoLoginFailedException.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,7 @@ | ||
package kr.mafoo.user.exception; | ||
|
||
public class KakaoLoginFailedException extends DomainException { | ||
public KakaoLoginFailedException() { | ||
super(ErrorCode.KAKAO_LOGIN_FAILED); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
user-service/src/main/java/kr/mafoo/user/exception/TokenExpiredException.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,7 @@ | ||
package kr.mafoo.user.exception; | ||
|
||
public class TokenExpiredException extends DomainException { | ||
public TokenExpiredException() { | ||
super(ErrorCode.TOKEN_EXPIRED); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
user-service/src/main/java/kr/mafoo/user/exception/TokenTypeMismatchException.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,7 @@ | ||
package kr.mafoo.user.exception; | ||
|
||
public class TokenTypeMismatchException extends DomainException { | ||
public TokenTypeMismatchException() { | ||
super(ErrorCode.TOKEN_TYPE_MISMATCH); | ||
} | ||
} |
Oops, something went wrong.