IT 알쓸신잡

그누보드에서 소셜 로그인 연동 해제 [구글] 본문

Development

그누보드에서 소셜 로그인 연동 해제 [구글]

솦트웰러 2023. 3. 15. 10:44
728x90
반응형

카카오, 네이버에 이어 그누보드에서 구글 소셜로그인 연동 해제에 대해 알아보도록 하겠습니다

 

2023.03.08 - [Development] - 그누보드에서 소셜 로그인 연동 해제 [카카오]

 

그누보드에서 소셜 로그인 연동 해제 [카카오]

그누보드에서 소셜 로그인 적용 테스트 중, 회원 탈퇴 시 소셜 로그인 연동 해제를 시켜줘야 하는데 DB에서는 삭제가 되지만 연동은 해제가 안되더군요... 확인은 탈퇴 후 재가입 시 사용자에게

swmaster.tistory.com

 

이전 글을 보셨으면,

www/plugin/social/includes/functions.php 파일에,

social_member_link_delete 함수에서 DB에 소셜 계정 정보를 삭제 후, unlink 함수 호출이 되는 부분이 들어가 있을겁니다.

 

1. Google.php 에 unlink 함수 만들기

www/plugin/social/Hybrid/Providers/Google.php 파일에 아래와 같이 unlink 함수를 만들어 줍니다.

 

  function unlink($code)
  {

    $params = array(
        "grant_type"    => "authorization_code",
        "client_id"     => $this->api->client_id,
        "client_secret" => $this->api->client_secret,
        "token"         => $this->api->access_token,
        "code"          => $code
    );

    $revokeURL = "https://oauth2.googleapis.com/revoke?token=".$this->api->access_token;

    $http_info = array();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $revokeURL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    $response = curl_exec($ch); //run

    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get HTTP code

    curl_close($ch);

    if ($httpCode == 200)
    {
      echo "<script>alert('$httpCode => Success');</script>";
      return "Success";
    }
    else
      return "Fail";
  }

Google 소셜로그인은 카카오, 네이버와 다르게 별도의 request 함수가 없습니다.

그래서 curl 관련 함수를 직접 적용하여 사용했습니다.

 

구글 소셜로그인 연동 해제의 가장 중요한 키포인트는 revokeURL입니다.

$revokeURL = " https://oauth2.googleapis.com/revoke?token= ".$this->api->access_token;

 

URL에 access_token 값을 전송하도록 하고, 파라미터에 client_id / client_secret / token / code 를 포함하도록 합니다.

 

2. 결과 확인

구글은 별도의 동의확인 창이 안뜨더군요. 신규 가입도 마찬가지구요...

하지만 위 소스처럼 curl 수행 후 httpCode 가 200번일 경우 Success라고 합니다

그누보드에서 구글 소셜로그인 연동 해제

연동 해제 시 $httpCode 가 200번일 경우 메세지를 출력하도록 했는데 성공적으로 출력이 되는군요.

 

이상으로 그누보드에서 구글 소셜로그인 연동 해제 기능을 추가하는 방법에 대해 알아보았습니다.

728x90
반응형
Comments