Skip to content

Commit

Permalink
Merge pull request #28 from SunjooAI/#28/feature
Browse files Browse the repository at this point in the history
feat : 구글 로그인 토큰 전송 api 추가
  • Loading branch information
baesunyoung6767 authored Jul 7, 2024
2 parents e94a3d1 + a5dc30d commit bd20e40
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.sql.SQLException;

Expand Down Expand Up @@ -75,6 +80,25 @@ public ResponseEntity googleLogin(@RequestBody GoogleLoginRequestDto requestDto,
}
}

@PostMapping("/login/google-token")
public ResponseEntity googleLogin(@RequestBody GoogleTokenRequestDto requestDto) {
try {
log.info("구글 로그인 요청 : " + requestDto.getToken());
RestTemplate restTemplate = new RestTemplate();
String GOOGLE_USERINFO_REQUEST_URL="https://www.googleapis.com/oauth2/v1/userinfo";

HttpHeaders headers = new HttpHeaders();
headers.add("Authorization","Bearer "+ requestDto.getToken());

HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(headers);
ResponseEntity<String> response= restTemplate.exchange(GOOGLE_USERINFO_REQUEST_URL, HttpMethod.GET,request,String.class);
return response;
}catch (Exception e) {
e.printStackTrace();
return ResponseEntity.internalServerError().build();
}
}

@GetMapping("/userinfo")
public ResponseEntity getUserInfo(@AuthenticationPrincipal UserDetailsImpl userDetails) {
log.info("정보 조회 요청 회원 번호 : " + userDetails.getUserNo());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sunjoo.auth.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter
@AllArgsConstructor
@NoArgsConstructor
public class GoogleTokenRequestDto {
String token;
}

0 comments on commit bd20e40

Please sign in to comment.