-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthController.java
100 lines (91 loc) · 4.24 KB
/
AuthController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.dilly.auth.api;
import com.dilly.application.KakaoService;
import com.dilly.auth.application.AuthService;
import com.dilly.auth.dto.request.#Request;
import com.dilly.auth.dto.response.SignInResponse;
import com.dilly.exception.ErrorCode;
import com.dilly.global.response.DataResponseDto;
import com.dilly.global.swagger.ApiErrorCodeExample;
import com.dilly.global.swagger.ApiErrorCodeExamples;
import com.dilly.jwt.JwtService;
import com.dilly.jwt.dto.JwtRequest;
import com.dilly.jwt.dto.JwtResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "OAuth 관련 API")
@RestController
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;
private final JwtService jwtService;
private final KakaoService kakaoService;
@Operation(summary = "회원 가입", description = "provider는 kakao 또는 apple")
@ApiErrorCodeExamples({
ErrorCode.UNSUPPORTED_LOGIN_TYPE,
ErrorCode.MEMBER_ALREADY_EXIST,
ErrorCode.KAKAO_SERVER_ERROR,
ErrorCode.APPLE_FAILED_TO_GET_TOKEN,
ErrorCode.APPLE_FAILED_TO_GET_PUBLIC_KEY,
ErrorCode.APPLE_FAILED_TO_GET_INFO,
ErrorCode.APPLE_FAILED_TO_GET_CLIENT_SECRET,
ErrorCode.APPLE_FAILED_TO_REVOKE_ACCOUNT,
ErrorCode.INVALID_INPUT_VALUE
})
@PostMapping("/sign-up")
public DataResponseDto<JwtResponse> #(
@RequestHeader("Authorization") @Schema(description = "Bearer prefix 제외해주세요") String providerAccessToken,
@RequestBody @Valid #Request #Request) {
return DataResponseDto.from(authService.#(providerAccessToken, #Request));
}
@Operation(summary = "로그인", description = "status는 NOT_REGISTERED, REGISTERED, WITHDRAWAL, BLACKLIST")
@ApiErrorCodeExamples({
ErrorCode.UNSUPPORTED_LOGIN_TYPE
})
@GetMapping("/sign-in/{provider}")
public DataResponseDto<SignInResponse> signIn(
@PathVariable(name = "provider")
@Schema(allowableValues = {"kakao", "apple"})
String provider,
@RequestHeader("Authorization")
@Schema(description = "kakao는 accessToken, apple은 identityToken을 Bearer prefix 없이 넣어주세요.")
String providerAccessToken) {
return DataResponseDto.from(authService.signIn(provider, providerAccessToken));
}
@Operation(summary = "회원 탈퇴")
@DeleteMapping("/withdraw")
public DataResponseDto<String> withdraw() {
return DataResponseDto.from(authService.withdraw());
}
@Operation(hidden = true)
@PostMapping("/withdraw/kakao")
public DataResponseDto<String> externalWithdraw(
@RequestHeader(name = "Authorization") String authorization,
@RequestParam(name = "user_id") String userId
) {
return DataResponseDto.from(authService.externalWithdraw(authorization, userId));
}
@Operation(summary = "JWT 만료 시 재발급")
@ApiErrorCodeExample(ErrorCode.INVALID_REFRESH_TOKEN)
@PostMapping("/reissue")
public DataResponseDto<JwtResponse> reissue(@RequestBody JwtRequest jwtRequest) {
return DataResponseDto.from(jwtService.reissueJwt(jwtRequest));
}
@Operation(summary = "카카오 code로 token 정보 조회", description = "서버에서 테스트용으로 사용하는 API입니다.")
@GetMapping("/token/kakao/{code}")
public DataResponseDto<String> getKakaoAccessToken(@PathVariable(name = "code") String code) {
return DataResponseDto.from(kakaoService.getKakaoAccessToken(code));
}
}