Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 이메일 인증 SES로 구현부 변경 #139

Merged
merged 1 commit into from
Nov 20, 2024
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: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ dependencies {
// // https://mvnrepository.com/artifact/org.flywaydb/flyway-mysql
// implementation 'org.flywaydb:flyway-mysql:10.15.2'

// Gmail
implementation 'com.google.api-client:google-api-client:2.0.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.34.1'
implementation 'com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0'
implementation 'javax.mail:mail:1.4.7'

// QueryDSL
def querydslVersion = "5.0.0"
implementation "com.querydsl:querydsl-jpa:${querydslVersion}:jakarta"
Expand All @@ -67,6 +61,9 @@ dependencies {

// FCM
implementation 'com.google.firebase:firebase-admin:9.4.1'

// SES
implementation 'com.amazonaws:aws-java-sdk-ses:1.12.778'
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.ioteatime.meonghanyangserver.auth.dto.request.LoginRequest;
import org.ioteatime.meonghanyangserver.auth.mapper.AuthEntityMapper;
import org.ioteatime.meonghanyangserver.auth.mapper.AuthResponseMapper;
import org.ioteatime.meonghanyangserver.clients.google.GoogleMailClient;
import org.ioteatime.meonghanyangserver.clients.ses.SesClient;
import org.ioteatime.meonghanyangserver.common.exception.BadRequestException;
import org.ioteatime.meonghanyangserver.common.exception.NotFoundException;
import org.ioteatime.meonghanyangserver.common.exception.UnauthorizedException;
Expand All @@ -30,13 +30,13 @@
@Service
@RequiredArgsConstructor
public class AuthService {
private final MemberRepository memberRepository;
private final GoogleMailClient googleMailClient;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final JwtUtils jwtUtils;
private final SesClient sesClient;
private final MemberRepository memberRepository;
private final GroupMemberRepository deviceRepository;
private final EmailCodeRepository emailCodeRepository;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final RefreshTokenRepository refreshTokenRepository;
private final GroupMemberRepository deviceRepository;

public LoginResponse login(LoginRequest loginRequest) {
MemberEntity memberEntity =
Expand Down Expand Up @@ -84,7 +84,7 @@ public void send(String email) {
<p>%s</p>
"""
.formatted(code);
googleMailClient.sendMail(email, mailSubject, mailContent);
sesClient.sendEmail(email, mailSubject, mailContent);
}

private static String getCode() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.ioteatime.meonghanyangserver.clients.ses;

import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.model.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class SesClient {
@Value("${google.official-gmail}")
private String officialGmail;

private final AmazonSimpleEmailService emailService;

public void sendEmail(String email, String subject, String body) {
final String FROM = officialGmail;
final String TO = email;
final String SUBJECT = subject;
final String HTMLBODY = body;

SendEmailRequest request =
new SendEmailRequest()
.withDestination(new Destination().withToAddresses(TO))
.withMessage(
new Message()
.withBody(
new Body()
.withHtml(
new Content()
.withCharset("UTF-8")
.withData(HTMLBODY)))
.withSubject(
new Content()
.withCharset("UTF-8")
.withData(SUBJECT)))
.withSource(FROM);
emailService.verifyEmailAddress(new VerifyEmailAddressRequest().withEmailAddress(email));
emailService.sendEmail(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.amazonaws.regions.Regions;
import com.amazonaws.services.kinesisvideo.AmazonKinesisVideo;
import com.amazonaws.services.kinesisvideo.AmazonKinesisVideoClient;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -17,6 +19,12 @@ public class AwsConfig {
@Value("${aws.kvs.secret-key}")
private String kvsSecretKey;

@Value("${aws.ses.access-key}")
private String sesAccessKey;

@Value("${aws.ses.secret-key}")
private String sesSecretKey;

@Bean
public AmazonKinesisVideo amazonKinesisVideo() {
AWSCredentials awsCredentials =
Expand All @@ -37,4 +45,25 @@ public String getAWSSecretKey() {
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}

@Bean
public AmazonSimpleEmailService amazonSimpleEmailService() {
AWSCredentials awsCredentials =
new AWSCredentials() {
@Override
public String getAWSAccessKeyId() {
return sesAccessKey;
}

@Override
public String getAWSSecretKey() {
return sesSecretKey;
}
};

return AmazonSimpleEmailServiceClient.builder()
.withRegion(Regions.AP_NORTHEAST_2)
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ spring:
multipart:
location: C:\\multipart\\uploads\\
max-file-size: 10MB
max-request-size: 10MB
max-request-size: 10MB

logging:
level:
root: debug
6 changes: 5 additions & 1 deletion src/main/resources/application-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ token:

google:
service-account: ${GCP_SERVICE_ACCOUNT}
gmail-service-account: ${GMAIL_SERVICE_ACCOUNT}
official-gmail: ${OFFICIAL_GMAIL}
application-credentials: ${GOOGLE_APPLICATION_CREDENTIALS}

aws:
kvs:
access-key: ${AWS_KVS_ACCESS_KEY}
secret-key: ${AWS_KVS_SECRET_KEY}
secret-key: ${AWS_KVS_SECRET_KEY}
ses:
access-key: ${AWS_SES_ACCESS_KEY}
secret-key: ${AWS_SES_SECRET_KEY}
Loading