Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ jobs:
JAR=$(ls build/libs/*.jar | head -n 1)
cp "$JAR" app.jar

- name: Create Firebase service account file
run: |
mkdir -p firebase
echo "${{ secrets.FCM }}" > firebase/tinybite_fcm.json

- name: Compute image name (change to lowercase)
id: img
run: echo "name=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT

- name: Log in to GHCR
- name: Log in to GHCR registry: ${{ env.REGISTRY }}

uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ita.tinybite.domain.user.constant.PlatformType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record GoogleAndAppleSignupRequest(
@NotBlank(message = "idToken์€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค")
Expand All @@ -12,7 +13,7 @@ public record GoogleAndAppleSignupRequest(
String nickname,
@NotBlank(message = "์œ„์น˜ ์ •๋ณด ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค")
String location,
@NotBlank(message = "ํ”Œ๋žซํผ์ •๋ณด๋Š” ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค")
@NotNull(message = "ํ”Œ๋žซํผ์ •๋ณด๋Š” ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค")
PlatformType platform
) {
}
33 changes: 30 additions & 3 deletions src/main/java/ita/tinybite/domain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.jwt.JwtException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -47,8 +49,8 @@ public class AuthService {
private final JwtDecoder appleJwtDecoder;
private final NicknameGenerator nicknameGenerator;

// @Value("${apple.client-id}")
// private String appleClientId;
@Value("${apple.client-id}")
private String appleClientId;

@Value("${google.android-id}")
private String googleAndroidId;
Expand Down Expand Up @@ -224,10 +226,35 @@ private String getEmailFromIdToken(String idToken, PlatformType platformType, Lo

} catch (GeneralSecurityException | IOException e) {
throw BusinessException.of(AuthErrorCode.GOOGLE_LOGIN_ERROR);
} catch (Exception e) {
throw BusinessException.of(AuthErrorCode.INVALID_TOKEN);
}
}
case APPLE -> {
//TODO Apple ๊ตฌํ˜„ ์˜ˆ์ •
String clientId = appleClientId;

try {
Jwt jwt = appleJwtDecoder.decode(idToken);

if(!"https://appleid.apple.com".equals(jwt.getIssuer().toString())) {
throw BusinessException.of(AuthErrorCode.INVALID_TOKEN);
}

String aud = jwt.getAudience().get(0);
if (!aud.equals(clientId)) {
throw BusinessException.of(AuthErrorCode.INVALID_TOKEN);
}

Object emailObject = jwt.getClaims().get("email");
if(emailObject == null) {
throw BusinessException.of(AuthErrorCode.NOT_EXISTS_EMAIL);
}
return emailObject.toString();
} catch (JwtException e) {
throw BusinessException.of(AuthErrorCode.INVALID_TOKEN);
} catch (Exception e) {
throw BusinessException.of(AuthErrorCode.APPLE_LOGIN_ERROR);
}
}
}
return null;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ita/tinybite/global/config/FcmConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.FileSystemResource;

@Slf4j
@Configuration
Expand All @@ -31,7 +30,7 @@ public void initialize() {
return;
}
try {
ClassPathResource resource = new ClassPathResource(fcmConfigPath);
ClassPathResource resource = new ClassPathResource(fcmConfigPath);
try (InputStream stream = resource.getInputStream()) {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(stream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public enum AuthErrorCode implements ErrorCode {
GOOGLE_LOGIN_ERROR(HttpStatus.BAD_REQUEST, "GOOGLE_LOGIN_ERROR", "๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),
APPLE_LOGIN_ERROR(HttpStatus.BAD_REQUEST, "APPLE_LOGIN_ERROR", "์• ํ”Œ ๋กœ๊ทธ์ธ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),

INVALID_PLATFORM(HttpStatus.BAD_REQUEST, "INVALID_PLATFORM", "์˜ฌ๋ฐ”๋ฅธ ํ”Œ๋žซํผ์ด ์•„๋‹™๋‹ˆ๋‹ค. (Android, iOS)");
INVALID_PLATFORM(HttpStatus.BAD_REQUEST, "INVALID_PLATFORM", "์˜ฌ๋ฐ”๋ฅธ ํ”Œ๋žซํผ์ด ์•„๋‹™๋‹ˆ๋‹ค. (Android, iOS)"),
NOT_EXISTS_EMAIL(HttpStatus.BAD_REQUEST, "NOT_EXISTS_EMAIL", "์• ํ”Œ ์ด๋ฉ”์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
;

private final HttpStatus httpStatus;
private final String code;
Expand Down
9 changes: 1 addition & 8 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
jpa:
show-sql: true
hibernate:
ddl-auto: create-drop # ๊ฐœ๋ฐœ: update, ์šด์˜: validate ๋˜๋Š” none
ddl-auto: update # ๊ฐœ๋ฐœ: update, ์šด์˜: validate ๋˜๋Š” none

data:
redis:
Expand All @@ -22,10 +22,3 @@ spring:
kakao:
client-id: ${KAKAO_CLIENT_ID}
redirect-uri: ${KAKAO_REDIRECT_URI}

naver:
client-id: ${NAVER_CLIENT_ID}
secret: ${NAVER_CLIENT_SECRET}

fcm:
file_path: ${DEV_FCM_PATH}
15 changes: 10 additions & 5 deletions src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ spring:
kakao:
client-id: ${KAKAO_CLIENT_ID}
redirect-uri: ${KAKAO_REDIRECT_URI}

google:
android-id: ${GOOGLE_ANDROID_CLIENT_ID}
ios-id: ${GOOGLE_IOS_CLIENT_ID}

naver:
client-id: ${NAVER_CLIENT_ID}
secret: ${NAVER_CLIENT_SECRET}
google:
android-id: ${GOOGLE_ANDROID_CLIENT_ID}
ios-id: ${GOOGLE_IOS_CLIENT_ID}

fcm:
file_path: firebase/tinybite_fcm.json
#apple:
# client-id: ${APPLE_CLIENT_ID}
#

logging:
level:
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ sms:
api-key: ${SMS_API_KEY}
api-secret: ${SMS_API_SECRET}

apple:
client-id: ${APPLE_CLIENT_ID}

naver:
client-id: ${NAVER_CLIENT_ID}
secret: ${NAVER_CLIENT_SECRET}

fcm:
file_path: firebase/tinybite_fcm.json
url: https://fcm.googleapis.com/v1/projects/${FCM_PROJECT_ID}/messages:send
google_api: https://www.googleapis.com/auth/cloud-platform
project_id: ${FCM_PROJECT_ID}

google:
android-id: ${GOOGLE_ANDROID_CLIENT_ID}
ios-id: ${GOOGLE_IOS_CLIENT_ID}

#apple:
# client-id: ${APPLE_CLIENT_ID}
#