Google reCAPTCHA Secret Key 준비

가장 먼저 Google reCAPTCHA 관리자 페이지에서 발급받은 ReCAPTCHA v3용 Secret Key를 준비한다.

이 키는 백엔드에서 사용이 되어진다.

RECAPTCHA_SECRET=6LdTXC0sAAAAAFIWPxNirKSoNbA1KO72q4tTFa8c

ReCAPTCHA 적용 백엔드 코드

RestClientConfig

reCAPTCHA 토큰을 Google API에 전송하여 검증하고, RecaptchaResponse 객체를 반환을 하기 위해

필요한 설정 클래스 파일이다.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestClientConfig {

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

AuthController

@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {
    private final AuthService authService;

		// ...

    // 비밀번호 변경
    @PutMapping("/change/password")
    public ResponseEntity<String> changePassword(@RequestBody PasswordDto dto) {
        authService.changePassword(dto);
        return ResponseEntity.ok("비밀번호 변경 완료.");
    }

}

위 코드에서 @RequestBody로 데이터를 받는 이유는 민감한 정보이므로 그렇게 해줬다.