-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from boostcampwm2023/server/refactor/415
Auth 모듈 스프링 서버로 이전(~ing)
- Loading branch information
Showing
28 changed files
with
885 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,80 @@ | ||
name: Backend Spring CI | ||
# name: Backend Spring CI | ||
|
||
on: | ||
pull_request: | ||
branches: [develop] | ||
paths: | ||
- "server/spring/**" | ||
# on: | ||
# pull_request: | ||
# branches: [develop] | ||
# paths: | ||
# - "server/spring/**" | ||
|
||
defaults: | ||
run: | ||
working-directory: ./server/spring | ||
# defaults: | ||
# run: | ||
# working-directory: ./server/spring | ||
|
||
jobs: | ||
BACKEND-SPRING-CI: | ||
runs-on: ubuntu-20.04 | ||
# jobs: | ||
# BACKEND-SPRING-CI: | ||
# runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
# steps: | ||
# - name: Checkout | ||
# uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: "adopt" | ||
# - name: Set up JDK 17 | ||
# uses: actions/setup-java@v4 | ||
# with: | ||
# java-version: 17 | ||
# distribution: "adopt" | ||
|
||
- name: Create application.yml | ||
env: | ||
DB_HOST_IP: ${{ secrets.SERVER_ENV_DB_HOST_IP }} | ||
DB_PORT: ${{ secrets.SERVER_ENV_DB_PORT }} | ||
DB_USER_NAME: ${{ secrets.SERVER_ENV_DB_USER_NAME }} | ||
DB_PASSWORD: ${{ secrets.SERVER_ENV_DB_PASSWORD }} | ||
DB_DATABASE_NAME: ${{ secrets.SERVER_ENV_DB_DATABASE_NAME }} | ||
ACCESS_ID: ${{ secrets.SERVER_ENV_ACCESS_ID }} | ||
SECRET_ACCESS_KEY: ${{ secrets.SERVER_ENV_SECRET_ACCESS_KEY }} | ||
JWT_SECRET_KEY: ${{ secrets.SERVER_ENV_JWT_SECRET_KEY }} | ||
GREEN_EYE_SECRET_KEY: ${{secrets.GREEN_EYE_SECRET_KEY}} | ||
GREEN_EYE_REQUEST_URL: ${{secrets.GREEN_EYE_REQUEST_URL}} | ||
CLOUD_FUNCTIONS_EXECUTE_URL: ${{secrets.CLOUD_FUNCTIONS_EXECUTE_URL}} | ||
CLOUD_FUNCTIONS_REQUEST_URL: ${{secrets.CLOUD_FUNCTIONS_REQUEST_URL}} | ||
API_GW_ACCESS_KEY: ${{secrets.API_GW_ACCESS_KEY}} | ||
REFRESH_SECRET_KEY: ${{secrets.REFRESH_SECRET_KEY}} | ||
REDIS_HOST_IP: ${{secrets.REDIS_HOST_IP}} | ||
REDIS_PASSWORD: ${{secrets.REDIS_PASSWORD}} | ||
REDIS_PORT: ${{secrets.REDIS_PORT}} | ||
REDIS_TTL: ${{secrets.REDIS_TTL}} | ||
run: | | ||
touch application.yml | ||
echo "DB_HOST_IP=$DB_HOST_IP" >> application.yml | ||
echo "DB_PORT=$DB_PORT" >> application.yml | ||
echo "DB_USER_NAME=$DB_USER_NAME" >> application.yml | ||
echo "DB_PASSWORD=$DB_PASSWORD" >> application.yml | ||
echo "DB_DATABASE_NAME=$DB_DATABASE_NAME" >> application.yml | ||
echo "ACCESS_ID=$ACCESS_ID" >> application.yml | ||
echo "SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY" >> application.yml | ||
echo "JWT_SECRET_KEY=$JWT_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_SECRET_KEY=$GREEN_EYE_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_REQUEST_URL=$GREEN_EYE_REQUEST_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_EXECUTE_URL=$CLOUD_FUNCTIONS_EXECUTE_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_REQUEST_URL=$CLOUD_FUNCTIONS_REQUEST_URL" >> application.yml | ||
echo "API_GW_ACCESS_KEY=$API_GW_ACCESS_KEY" >> application.yml | ||
echo "REFRESH_SECRET_KEY=$REFRESH_SECRET_KEY" >> application.yml | ||
echo "REDIS_HOST_IP=$REDIS_HOST_IP" >> application.yml | ||
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> application.yml | ||
echo "REDIS_PORT=$REDIS_PORT" >> application.yml | ||
echo "REDIS_TTL=$REDIS_TTL" >> application.yml | ||
# - name: Create application.properties | ||
# env: | ||
# DB_HOST_IP: ${{ secrets.SERVER_ENV_DB_HOST_IP }} | ||
# DB_PORT: ${{ secrets.SERVER_ENV_DB_PORT }} | ||
# DB_USER_NAME: ${{ secrets.SERVER_ENV_DB_USER_NAME }} | ||
# DB_PASSWORD: ${{ secrets.SERVER_ENV_DB_PASSWORD }} | ||
# DB_DATABASE_NAME: ${{ secrets.SERVER_ENV_DB_DATABASE_NAME }} | ||
# ACCESS_ID: ${{ secrets.SERVER_ENV_ACCESS_ID }} | ||
# SECRET_ACCESS_KEY: ${{ secrets.SERVER_ENV_SECRET_ACCESS_KEY }} | ||
# JWT_SECRET_KEY: ${{ secrets.SERVER_ENV_JWT_SECRET_KEY }} | ||
# GREEN_EYE_SECRET_KEY: ${{secrets.GREEN_EYE_SECRET_KEY}} | ||
# GREEN_EYE_REQUEST_URL: ${{secrets.GREEN_EYE_REQUEST_URL}} | ||
# CLOUD_FUNCTIONS_EXECUTE_URL: ${{secrets.CLOUD_FUNCTIONS_EXECUTE_URL}} | ||
# CLOUD_FUNCTIONS_REQUEST_URL: ${{secrets.CLOUD_FUNCTIONS_REQUEST_URL}} | ||
# API_GW_ACCESS_KEY: ${{secrets.API_GW_ACCESS_KEY}} | ||
# REFRESH_SECRET_KEY: ${{secrets.REFRESH_SECRET_KEY}} | ||
# REDIS_HOST_IP: ${{secrets.REDIS_HOST_IP}} | ||
# REDIS_PASSWORD: ${{secrets.REDIS_PASSWORD}} | ||
# REDIS_PORT: ${{secrets.REDIS_PORT}} | ||
# REDIS_TTL: ${{secrets.REDIS_TTL}} | ||
# run: | | ||
# touch application.properties | ||
# echo "DB_HOST_IP=$DB_HOST_IP" >> application.properties | ||
# echo "DB_PORT=$DB_PORT" >> application.properties | ||
# echo "DB_USER_NAME=$DB_USER_NAME" >> application.properties | ||
# echo "DB_PASSWORD=$DB_PASSWORD" >> application.properties | ||
# echo "DB_DATABASE_NAME=$DB_DATABASE_NAME" >> application.properties | ||
# echo "ACCESS_ID=$ACCESS_ID" >> application.properties | ||
# echo "SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY" >> application.properties | ||
# echo "JWT_SECRET_KEY=$JWT_SECRET_KEY" >> application.properties | ||
# echo "GREEN_EYE_SECRET_KEY=$GREEN_EYE_SECRET_KEY" >> application.properties | ||
# echo "GREEN_EYE_REQUEST_URL=$GREEN_EYE_REQUEST_URL" >> application.properties | ||
# echo "CLOUD_FUNCTIONS_EXECUTE_URL=$CLOUD_FUNCTIONS_EXECUTE_URL" >> application.properties | ||
# echo "CLOUD_FUNCTIONS_REQUEST_URL=$CLOUD_FUNCTIONS_REQUEST_URL" >> application.properties | ||
# echo "API_GW_ACCESS_KEY=$API_GW_ACCESS_KEY" >> application.properties | ||
# echo "REFRESH_SECRET_KEY=$REFRESH_SECRET_KEY" >> application.properties | ||
# echo "REDIS_HOST_IP=$REDIS_HOST_IP" >> application.properties | ||
# echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> application.properties | ||
# echo "REDIS_PORT=$REDIS_PORT" >> application.properties | ||
# echo "REDIS_TTL=$REDIS_TTL" >> application.properties | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
# - name: Gradle Caching | ||
# uses: actions/cache@v4 | ||
# with: | ||
# path: | | ||
# ~/.gradle/caches | ||
# ~/.gradle/wrapper | ||
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
|
||
- name: Test with Gradle | ||
run: ./gradlew --info test | ||
# - name: Grant execute permission for gradlew | ||
# run: chmod +x gradlew | ||
|
||
# - name: Test with Gradle | ||
# run: ./gradlew --info test |
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,2 +1,5 @@ | ||
# Mac Os | ||
.DS_Store | ||
.DS_Store | ||
|
||
# VSC setting | ||
.vscode/** |
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
45 changes: 45 additions & 0 deletions
45
server/spring/src/main/java/catchytape/spring/auth/config/RedisConfig.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,45 @@ | ||
package catchytape.spring.auth.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Value("${spring.data.redis.password}") | ||
private String password; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); | ||
|
||
config.setHostName(host); | ||
config.setPort(port); | ||
config.setPassword(password); | ||
|
||
return new LettuceConnectionFactory(config); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate() { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
|
||
return redisTemplate; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
server/spring/src/main/java/catchytape/spring/auth/controller/AuthController.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,61 @@ | ||
package catchytape.spring.auth.controller; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import catchytape.spring.auth.controller.dto.UserSignupRequest; | ||
import catchytape.spring.auth.controller.dto.UserAuthResponse; | ||
import catchytape.spring.auth.controller.dto.UserLoginRequest; | ||
import catchytape.spring.auth.controller.dto.UserRefreshRequest; | ||
import catchytape.spring.auth.service.AuthService; | ||
import catchytape.spring.auth.service.RedisService; | ||
import catchytape.spring.common.exception.CatchyException; | ||
import catchytape.spring.recentPlayed.RecentPlayed; | ||
import catchytape.spring.user.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/users") | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
|
||
@PostMapping(value="/signup", consumes="application/json;charset=UTF-8") | ||
public ResponseEntity<UserAuthResponse> signup(@RequestBody UserSignupRequest request) throws CatchyException{ | ||
log.info("POST /users/signup - body = nickname: " + request.nickname()); | ||
|
||
return ResponseEntity.ok(authService.signup(request.idToken(), request.nickname())); | ||
} | ||
|
||
@PostMapping(value="/login", consumes="application/json;charset=UTF-8") | ||
public ResponseEntity<UserAuthResponse> login(@RequestBody UserLoginRequest request) throws CatchyException { | ||
log.info("POST /users/signup - body = idToken: "); | ||
|
||
return ResponseEntity.ok(authService.login(request.idToken())); | ||
} | ||
|
||
@PostMapping(value="/refresh", consumes="application/json;charset=UTF-8") | ||
public ResponseEntity<UserAuthResponse> refresh(@RequestBody UserRefreshRequest request) throws CatchyException { | ||
log.info("POST /users/refresh - body = refreshToken: ", request.refreshToken()); | ||
|
||
return ResponseEntity.ok(this.authService.refreshToken(request.refreshToken())); | ||
} | ||
|
||
@GetMapping("/test") | ||
public ResponseEntity<User> test() throws CatchyException { | ||
return ResponseEntity.ok(this.authService.test()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
server/spring/src/main/java/catchytape/spring/auth/controller/dto/UserAuthResponse.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 catchytape.spring.auth.controller.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserAuthResponse(String accessToken, String refreshToken) { | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
server/spring/src/main/java/catchytape/spring/auth/controller/dto/UserLoginRequest.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,3 @@ | ||
package catchytape.spring.auth.controller.dto; | ||
|
||
public record UserLoginRequest(String idToken) {} |
3 changes: 3 additions & 0 deletions
3
server/spring/src/main/java/catchytape/spring/auth/controller/dto/UserRefreshRequest.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,3 @@ | ||
package catchytape.spring.auth.controller.dto; | ||
|
||
public record UserRefreshRequest(String refreshToken) {} |
4 changes: 4 additions & 0 deletions
4
server/spring/src/main/java/catchytape/spring/auth/controller/dto/UserSignupRequest.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,4 @@ | ||
package catchytape.spring.auth.controller.dto; | ||
|
||
public record UserSignupRequest(String nickname, String idToken) { | ||
} |
Oops, something went wrong.