11package com .back .domain .member .service ;
22
33import com .back .domain .member .entity .Member ;
4+ import com .back .global .exception .CustomException ;
5+ import com .back .global .exception .ErrorCode ;
46import com .back .standard .util .Ut ;
57import org .springframework .beans .factory .annotation .Value ;
68import org .springframework .stereotype .Service ;
79
10+ import java .net .URI ;
811import java .net .http .HttpClient ;
12+ import java .net .http .HttpRequest ;
13+ import java .net .http .HttpResponse ;
914import java .util .Map ;
1015
1116@ Service
@@ -16,22 +21,49 @@ public class AuthService {
1621 @ Value ("${custom.accessToken.expirationSeconds}" )
1722 private int accessTokenExpirationSeconds ;
1823
24+ private final String kakaoURL = "https://kapi.kakao.com/v1/user/unlink" ;
25+ private final String googleURL = "https://oauth2.googleapis.com/revoke" ;
26+ private final String naverURL = "https://nid.naver.com/oauth2.0/token" ;
27+
28+ @ Value ("${SPRING__SECURITY__OAUTH2__CLIENT__REGISTRATION__NAVER__CLIENT_ID}" )
29+ private String naverClientId ;
30+ @ Value ("${SPRING__SECURITY__OAUTH2__CLIENT__REGISTRATION__NAVER__CLIENT_SECRET}" )
31+ private String naverClientSecret ;
32+
1933 public void delete_social (String provider , String accessToken ) {
2034 HttpClient client = HttpClient .newHttpClient ();
2135 try {
36+ HttpRequest request = null ;
2237 switch (provider ) {
2338 case "KAKAO" -> {
24-
39+ request = HttpRequest .newBuilder ()
40+ .uri (URI .create (kakaoURL ))
41+ .header ("Authorization" , "Bearer " + accessToken )
42+ .POST (HttpRequest .BodyPublishers .noBody ())
43+ .build ();
2544 }
2645 case "GOOGLE" -> {
27-
46+ request = HttpRequest .newBuilder ()
47+ .uri (URI .create (googleURL + "?token=" + accessToken ))
48+ .POST (HttpRequest .BodyPublishers .noBody ())
49+ .build ();
2850 }
2951 case "NAVER" -> {
30-
52+ request = HttpRequest .newBuilder ()
53+ .uri (URI .create (naverURL +
54+ "?grant_type=delete" +
55+ "&access_token=" + accessToken +
56+ "&client_id=" + naverClientId +
57+ "&client_secret=" + naverClientSecret
58+ ))
59+ .POST (HttpRequest .BodyPublishers .noBody ())
60+ .build ();
3161 }
3262 }
63+ HttpResponse <String > response = client .send (request , HttpResponse .BodyHandlers .ofString ());
64+ System .out .printf ("[회원 탈퇴] Code: %s / Body: %s\n " , response .statusCode (), response .body ());
3365 } catch (Exception e ) {
34-
66+ throw new CustomException ( ErrorCode . INTERNAL_SERVER_ERROR , "[Member] Fail: 소셜 탈퇴" );
3567 }
3668 }
3769
0 commit comments