-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 회원 엔티티 생성 및 테스트코드 추가 * feat: 카카오 OAuth 환경변수 추가 및 클래스 바인딩 * feat: authorization code를 받기 위한 queryString generator 추가 * feat: Authorization code의 parameter 만드는 로직 분리 및 테스트 코드 추가 * feat: 회원 가입/로그인 요청 api 및 소셜 로그인 페이지 반환 * refactor: member관련 클래스 네이밍과 폴더 위치 변경 * refactor: 로그인 페이지 요청 방식 Resttemplate -> response (redirect)하도록 변경 * style: 코드 포맷 재적용 및 사용하지 않는 클래스 삭제 * chore: config 파일 업데이트 * refactor: 테스트 코드 추가 및 코드 포맷 재적용 * refactor: 사용하지 않는 코드 제거 * refactor: CRLF -> LF로 변경 * fix: config 커밋, config 최근 커밋으로 변경 * feat: 테스트 코드 추가 및 패키지 구조 변경 * refactor: revert merge * fix: merge confilt해결 및 예외처리 추가 * test: oauth properties가 없을 때의 테스트코드 추가 * feat: 코드리뷰에 따른 기능 분리 및 테스트 코드 변경 * fix: 테스트코드 관련 code smell 제거 * feat: Authorization grant 받기 예외 코드 및 테스트 코드 추가 * feat: Authorization Token 요청 및 반환 코드, 에러 반환 테스트 코드 추가 * refactor: AuthenticationService에서 서버에 요청보내는 로직 OAuth2AuthorizationServerRequestService로 분리 * test: 로그인 요청 테스트 코드 추가 * feat: 토큰 발급 요청 기능 테스트 코드 추가 및 RestTemplate 필드변수로 변경 * test: restTemplate 및 서비스 테스트 추가 * refactor: 에러 메세지 이름 변경 * refacotr: 변수명 및 entity default 명 변경 * feat: 토큰 정보 조회 기능 및 테스트 추가 * feat: 사용자 토큰 정보 조회 및 테스트 코드 & Resttemplate 테크트 코드 변경 * fix: encoding, formatting, tab 문제로 인한 파일 삭제 후 다시 작성 * feat: JWT 토큰 제공 서비스 및 테스트 코드 추가 * feat: 토큰 인증 코드 및 테스트 코드 작성 * feat: 로그인 및 회원가입 기능 추가 - 회원의 socialId string -> long으로 변경 * feat: 회원 로그인 테스트 코드 추가 * chore: 코드 포메팅 재 설정 * feat: config 파일 업데이트 * feat: Window용 포트 redis 포트 변경 추가 * refacotr: develop 업데이트 사항 merge * refactor: develop 업데이트 부분 merge * fix: TimeConfig 삭제 및 코드 스멜 변경 * refactor: 코르리뷰 반영
- Loading branch information
Showing
34 changed files
with
808 additions
and
178 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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/moabam/api/application/JwtAuthenticationService.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.moabam.api.application; | ||
|
||
import java.util.Base64; | ||
|
||
import org.json.JSONObject; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.global.config.TokenConfig; | ||
import com.moabam.global.error.exception.UnauthorizedException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import io.jsonwebtoken.ExpiredJwtException; | ||
import io.jsonwebtoken.Jwts; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class JwtAuthenticationService { | ||
|
||
private final TokenConfig tokenConfig; | ||
|
||
public boolean isTokenValid(String token) { | ||
try { | ||
Jwts.parserBuilder() | ||
.setSigningKey(tokenConfig.getKey()) | ||
.build() | ||
.parseClaimsJwt(token); | ||
return true; | ||
} catch (ExpiredJwtException expiredJwtException) { | ||
return false; | ||
} catch (Exception exception) { | ||
throw new UnauthorizedException(ErrorMessage.AUTHENTICATIE_FAIL); | ||
} | ||
} | ||
|
||
public String parseEmail(String token) { | ||
String claims = token.split("\\.")[1]; | ||
String decodeClaims = new String(Base64.getDecoder().decode(claims)); | ||
JSONObject jsonObject = new JSONObject(decodeClaims); | ||
|
||
return (String)jsonObject.get("id"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/moabam/api/application/JwtProviderService.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,41 @@ | ||
package com.moabam.api.application; | ||
|
||
import java.util.Date; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.global.config.TokenConfig; | ||
|
||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class JwtProviderService { | ||
|
||
private final TokenConfig tokenConfig; | ||
|
||
public String provideAccessToken(long id) { | ||
return generateToken(id, tokenConfig.getAccessExpire()); | ||
} | ||
|
||
public String provideRefreshToken(long id) { | ||
return generateToken(id, tokenConfig.getRefreshExpire()); | ||
} | ||
|
||
private String generateToken(long id, long expireTime) { | ||
Date issueDate = new Date(); | ||
Date expireDate = new Date(issueDate.getTime() + expireTime); | ||
|
||
return Jwts.builder() | ||
.setHeaderParam("alg", "HS256") | ||
.setHeaderParam("typ", "JWT") | ||
.setIssuer(tokenConfig.getIss()) | ||
.setIssuedAt(issueDate) | ||
.setExpiration(expireDate) | ||
.claim("id", id) | ||
.signWith(tokenConfig.getKey(), SignatureAlgorithm.HS256) | ||
.compact(); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/moabam/api/domain/repository/MemberRepository.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package com.moabam.api.domain.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.entity.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> findBySocialId(Long id); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.moabam.api.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record LoginResponse( | ||
Long id, | ||
boolean isSignUp | ||
) { | ||
|
||
} |
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,32 @@ | ||
package com.moabam.api.dto; | ||
|
||
import com.moabam.api.domain.entity.Bug; | ||
import com.moabam.api.domain.entity.Member; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class MemberMapper { | ||
|
||
public static Member toMember(Long socialId, String nickName) { | ||
return Member.builder() | ||
.socialId(socialId) | ||
.nickname(nickName) | ||
.bug(Bug.builder().build()) | ||
.build(); | ||
} | ||
|
||
public static LoginResponse toLoginResponse(Long memberId) { | ||
return LoginResponse.builder() | ||
.id(memberId) | ||
.build(); | ||
} | ||
|
||
public static LoginResponse toLoginResponse(Long memberId, boolean isSignUp) { | ||
return LoginResponse.builder() | ||
.id(memberId) | ||
.isSignUp(isSignUp) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.