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

[FEAT,FIX] : 개발용 컨트롤러 추가 , 애플 로그인 탈퇴 수정 #45

Merged
merged 1 commit into from
Sep 15, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wakeUpTogetUp.togetUp.api.auth.service;

import com.amazonaws.util.IOUtils;
import com.nimbusds.jose.shaded.json.JSONObject;
import com.wakeUpTogetUp.togetUp.api.auth.LoginType;
import com.wakeUpTogetUp.togetUp.api.auth.apple.*;
Expand Down Expand Up @@ -118,9 +119,15 @@ public String createClientSecret() throws IOException{
}

private PrivateKey getPrivateKey() throws IOException {
ClassPathResource resource = new ClassPathResource("AuthKey_M992KTZK9V.p8");
String privateKey = new String(Files.readAllBytes(Paths.get(resource.getURI())));
Reader pemReader = new StringReader(privateKey);
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("AuthKey_M992KTZK9V.p8");

if (inputStream == null) {
throw new BaseException(Status.FILE_NOT_FOUND);
}

byte[] privateKeyBytes = IOUtils.toByteArray(inputStream);
Reader pemReader = new StringReader(new String(privateKeyBytes));
PEMParser pemParser = new PEMParser(pemReader);
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
PrivateKeyInfo object = (PrivateKeyInfo) pemParser.readObject();
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/dev/DevController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.wakeUpTogetUp.togetUp.api.dev;

import com.wakeUpTogetUp.togetUp.api.users.model.User;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "A-개발용")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/a-dev")
public class DevController {

private final DevService devService;


@Operation(summary = "유저 가져오기", description = "유저 아이디와 이름")
@ResponseBody
@GetMapping("/user")
public BaseResponse<List<User>> user() {


return new BaseResponse<>(Status.SUCCESS,devService.get());

}

@Operation(summary = "dev용 : accessToken 발금", description = "jwt 발급")
05AM marked this conversation as resolved.
Show resolved Hide resolved
@ResponseBody
@GetMapping("/login/dev")
public BaseResponse<String> join(@Parameter(description = "jwt 받고 싶은 유저의 ID") Integer userId) {

String jwt = devService.devGetJwt(userId);

return new BaseResponse<>(Status.SUCCESS,jwt);

}



}
33 changes: 33 additions & 0 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/dev/DevService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.wakeUpTogetUp.togetUp.api.dev;


import com.wakeUpTogetUp.togetUp.api.users.UserRepository;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import com.wakeUpTogetUp.togetUp.utils.JwtService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DevService {

private final UserRepository userRepository;
private final JwtService jwtService;
public List<User> get()
{
return userRepository.findAll();
}


public String devGetJwt(Integer userId) {

//accessToken 만들기
String accessToken = jwtService.generateAccessToken(userId);

return accessToken;
}


}
2 changes: 1 addition & 1 deletion src/main/java/com/wakeUpTogetUp/togetUp/common/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Status {

USER_NOT_FOUND(HttpStatus.NOT_FOUND,"존재하지 않는 유저 입니다."),
ALARM_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 알람 입니다."),
FILE_NOT_FOUND(HttpStatus.NOT_FOUND, "삭제할 파일을 찾을 수 없습니다."),
FILE_NOT_FOUND(HttpStatus.NOT_FOUND, "파일을 찾을 수 없습니다."),
ACCOUNT_DOESNT_EXISTS(HttpStatus.NOT_FOUND,"계정이 존재하지 않습니다."),
OBJECT_NOT_FOUND(HttpStatus.NOT_FOUND, "객체를 찾을 수 없습니다."),
UNSUPPORTED_MEDIA_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "지원하지 않는 파일 확장자 입니다."),
Expand Down
Loading