Skip to content

Commit

Permalink
feat: #11 [테스트전] OIDC Helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Dec 23, 2023
1 parent 5e43fec commit 97e52e4
Show file tree
Hide file tree
Showing 44 changed files with 574 additions and 131 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ dependencies {
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'

// feign
implementation platform("org.springframework.cloud:spring-cloud-dependencies:2021.0.5")
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'io.github.openfeign:feign-okhttp'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'mysql:mysql-connector-java:8.0.28'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.kcy.fitapet.domain.member.type.converter.RoleTypeConverter;
import com.kcy.fitapet.domain.model.Auditable;
import com.kcy.fitapet.domain.notification.domain.Notification;
import com.kcy.fitapet.domain.member.type.NotificationSetting;
import com.kcy.fitapet.domain.notification.type.NotificationType;
import com.kcy.fitapet.domain.oauth2.domain.OAuthID;
import com.kcy.fitapet.domain.oauth.domain.OAuthID;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kcy.fitapet.domain.member.type;
package com.kcy.fitapet.domain.member.domain;

import com.kcy.fitapet.domain.notification.type.NotificationType;
import jakarta.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kcy.fitapet.domain.member.dto.account;

import com.kcy.fitapet.domain.member.domain.Member;
import com.kcy.fitapet.domain.member.type.NotificationSetting;
import com.kcy.fitapet.domain.member.domain.NotificationSetting;
import com.kcy.fitapet.global.common.util.bind.Dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kcy.fitapet.domain.member.dto.auth;

import com.kcy.fitapet.domain.member.domain.Member;
import com.kcy.fitapet.domain.member.type.NotificationSetting;
import com.kcy.fitapet.domain.member.type.RoleType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.kcy.fitapet.global.common.response.code.StatusCode;
import com.kcy.fitapet.global.common.response.exception.GlobalErrorException;
import com.kcy.fitapet.global.common.util.jwt.JwtUtil;
import com.kcy.fitapet.global.common.util.jwt.entity.JwtUserInfo;
import com.kcy.fitapet.global.common.util.jwt.entity.SmsAuthInfo;
import com.kcy.fitapet.global.common.util.jwt.dto.JwtUserInfo;
import com.kcy.fitapet.global.common.util.jwt.dto.SmsAuthInfo;
import com.kcy.fitapet.global.common.redis.forbidden.ForbiddenTokenService;
import com.kcy.fitapet.global.common.redis.refresh.RefreshToken;
import com.kcy.fitapet.global.common.redis.refresh.RefreshTokenService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.kcy.fitapet.domain.member.domain.Member;
import com.kcy.fitapet.domain.model.Auditable;
import com.kcy.fitapet.domain.notification.type.NotificationType;
import com.kcy.fitapet.domain.notification.type.NotificationTypeConverter;
import com.kcy.fitapet.domain.notification.type.converter.NotificationTypeConverter;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kcy.fitapet.domain.notification.type;
package com.kcy.fitapet.domain.notification.type.converter;

import com.kcy.fitapet.domain.notification.type.NotificationType;
import com.kcy.fitapet.global.common.util.converter.AbstractLegacyEnumAttributeConverter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kcy.fitapet.domain.notification.type;
package com.kcy.fitapet.domain.notification.type.converter;

import com.kcy.fitapet.domain.notification.type.NotificationType;
import org.springframework.core.convert.converter.Converter;

public class NotificationTypeQueryConverter implements Converter<String, NotificationType> {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/kcy/fitapet/domain/oauth/api/OAuthApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.kcy.fitapet.domain.oauth.api;

import com.kcy.fitapet.domain.member.dto.auth.SignInReq;
import com.kcy.fitapet.domain.oauth.dto.OauthSignInReq;
import com.kcy.fitapet.domain.oauth.dto.OauthSignUpReq;
import com.kcy.fitapet.domain.oauth.service.OAuthService;
import com.kcy.fitapet.domain.oauth.type.ProviderType;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "OAuth API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/auth/oauth")
@Slf4j
public class OAuthApi {
private final OAuthService oAuthService;

@PostMapping("")
@PreAuthorize("isAnonymous()")
public void signIn(
@RequestParam("provider") ProviderType provider,
@RequestBody @Valid OauthSignInReq req
) {
if (ProviderType.NAVER.equals(provider)) {

} else {

}
}

@PostMapping("/{id}")
@PreAuthorize("isAnonymous()")
public void signUp(
@PathVariable("id") String id,
@RequestParam("provider") ProviderType provider,
@RequestBody @Valid OauthSignUpReq req
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kcy.fitapet.domain.oauth.dao;

import com.kcy.fitapet.domain.oauth.api.OAuthApi;
import com.kcy.fitapet.global.common.repository.ExtendedRepository;

public interface OAuthRepository extends ExtendedRepository<OAuthApi, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.kcy.fitapet.domain.oauth.domain;

import com.kcy.fitapet.domain.member.domain.Member;
import com.kcy.fitapet.domain.model.Auditable;
import com.kcy.fitapet.domain.oauth.type.ProviderType;
import com.kcy.fitapet.domain.oauth.type.converter.ProviderTypeConverter;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "OAUTH")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(of = {"id", "provider"})
public class OAuthAccount extends Auditable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "oauth_id")
private Long OAuthID;
@Convert(converter = ProviderTypeConverter.class)
private ProviderType provider;
private String email;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Builder
public OAuthAccount(Long id, Long OAuthID, ProviderType provider, String email, Member member) {
this.id = id;
this.OAuthID = OAuthID;
this.provider = provider;
this.email = email;
this.member = member;
}

public static OAuthAccount of(Long OAuthID, ProviderType provider, String email, Member member) {
return OAuthAccount.builder()
.OAuthID(OAuthID)
.provider(provider)
.email(email)
.member(member)
.build();
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/kcy/fitapet/domain/oauth/dto/OauthSignInReq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kcy.fitapet.domain.oauth.dto;

import jakarta.validation.constraints.NotEmpty;

public record OauthSignInReq(
@NotEmpty
String id,
@NotEmpty
String id_token
) {
}
13 changes: 13 additions & 0 deletions src/main/java/com/kcy/fitapet/domain/oauth/dto/OauthSignUpReq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kcy.fitapet.domain.oauth.dto;

import jakarta.validation.constraints.NotBlank;

public record OauthSignUpReq(
@NotBlank
String phone,
@NotBlank
String name,
@NotBlank
String uid
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.kcy.fitapet.domain.oauth.service;

import com.kcy.fitapet.domain.oauth.dao.OAuthRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Slf4j
public class OAuthService {
private final OAuthRepository oAuthRepository;

@Transactional
public void signUpByOIDC() {

}

@Transactional
public void signInByOIDC() {

}

@Transactional
public void signInByCode() {

}

@Transactional
public void signUpByCode() {

}
}
47 changes: 47 additions & 0 deletions src/main/java/com/kcy/fitapet/domain/oauth/type/ProviderType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.kcy.fitapet.domain.oauth.type;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.kcy.fitapet.global.common.util.converter.LegacyCommonType;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toMap;

@RequiredArgsConstructor
public enum ProviderType implements LegacyCommonType {
KAKAO("1", "카카오"),
GOOGLE("2", "구글"),
NAVER("2", "네이버"),
APPLE("3", "애플");

private final String code;
private final String type;

private static final Map<String, ProviderType> stringToEnum =
Stream.of(values()).collect(toMap(Object::toString, e -> e));


@Override
public String getCode() {
return code;
}

@JsonValue
public String getType() {
return type;
}

@JsonCreator
public static ProviderType fromString(String type) {
return stringToEnum.get(type.toUpperCase());
}

@Override
public String toString() {
return name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kcy.fitapet.domain.oauth.type.converter;

import com.kcy.fitapet.domain.oauth.type.ProviderType;
import com.kcy.fitapet.global.common.util.converter.AbstractLegacyEnumAttributeConverter;

public class ProviderTypeConverter extends AbstractLegacyEnumAttributeConverter<ProviderType> {
private static final String ENUM_NAME = "제공자";

public ProviderTypeConverter() {
super(ProviderType.class, false, ENUM_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kcy.fitapet.domain.oauth.type.converter;

import com.kcy.fitapet.domain.oauth.type.ProviderType;
import org.springframework.core.convert.converter.Converter;

public class ProviderTypeQueryConverter implements Converter<String, ProviderType> {
@Override
public ProviderType convert(String source) {
try {
return ProviderType.valueOf(source.toUpperCase());
} catch (IllegalArgumentException e) {
throw null;
}
}
}
15 changes: 0 additions & 15 deletions src/main/java/com/kcy/fitapet/domain/oauth2/api/OAuthApi.java

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/com/kcy/fitapet/domain/oauth2/domain/OAuthID.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kcy.fitapet.global.common.redis.refresh;

import com.kcy.fitapet.global.common.util.jwt.JwtUtil;
import com.kcy.fitapet.global.common.util.jwt.entity.JwtUserInfo;
import com.kcy.fitapet.global.common.util.jwt.dto.JwtUserInfo;
import com.kcy.fitapet.global.common.util.jwt.exception.AuthErrorCode;
import com.kcy.fitapet.global.common.util.jwt.exception.AuthErrorException;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kcy.fitapet.domain.member.domain.Member;
import com.kcy.fitapet.domain.member.type.RoleType;
import com.kcy.fitapet.global.common.util.jwt.entity.JwtUserInfo;
import com.kcy.fitapet.global.common.util.jwt.dto.JwtUserInfo;
import lombok.Builder;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
Expand Down
Loading

0 comments on commit 97e52e4

Please sign in to comment.