Error login menggunakan account kit fb

Assalamualaikum saya mau nanya disini ada yg pernah coba login account kit fb gak ? yg saya inginkan ketika kita login account kit fb via sms menggunakan nomer yang sesuai di database langsung masuk ke halaman admin web. saya coba kodingnya pake dokumentasi fb developer,video youtube <a href=' https://www.youtube.com/watch?v=o2-PCiiJzr4&feature=youtu.be'> https://www.youtube.com/watch?v=o2-PCiiJzr4&feature=youtu.be</a> tetep aja belum masuk gak ada tulisan error nya

file konfig.php

$server ="localhost";
$user   = "root";
$pw     = "";
$db1     = "kas";

$link   = new mysqli($server,$user,$pw,$db1);

file index.php


<head>
  <title>Login with Account Kit</title>
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="shortcut icon" href="ak-icon.png">
  <link rel="stylesheet" href="css.css">
  <!--Hotlinked Account Kit SDK-->
  <script src="https://sdk.accountkit.com/en_EN/sdk.js"></script>
  <style type="text/css">
  	body{
  font-family: helvetica;
}
.ac{
  text-align: center;
}
.buttons{
  max-width: 300px;
  margin: auto;
}
.buttons button{
  width: 100%;
  border-style: none;
  background-color: #4E86FF;
  color: #FFF;
  padding: 10px;
  margin: 5px 0;
}
  </style>
</head>
<body>

<h1 class="ac">Login with Account Kit</h1>
<p class="ac">This example shows you how to implement<br>Facebook Account Kit for web using PHP.</p>
<div class="buttons">
  <button onclick="phone_btn_onclick();">Login with SMS</button>
  <button onclick="email_btn_onclick();">Login with Email</button>
</div>
<form action="http://localhost/kas/ceklogin.php" method="POST" id="my_form">
  <input type="hidden" name="code" id="code">
  <input type="hidden" name="csrf_nonce" id="csrf_nonce">
</form>
<?php
}else{
?>
<h1 class="ac">Login with Account Kit</h1>
<p class="ac">The session with Facebook Account Kit is already started.</p>
<h3 class="ac">Your Information</h3>


</body>
<script>
  // initialize Account Kit with CSRF protection
  AccountKit_OnInteractive = function(){
    AccountKit.init(
      {
        appId:"<YOUR APP ID>',
        state:"abcd",
        version:"v1.0"
      }
      //If your Account Kit configuration requires app_secret, you have to include ir above
    );
  };
  // login callback
  function loginCallback(response) {
    console.log(response);
    if (response.status === "PARTIALLY_AUTHENTICATED") {
      document.getElementById("code").value = response.code;
      document.getElementById("csrf_nonce").value = response.state;
      document.getElementById("my_form").submit();
    }
    else if (response.status === "NOT_AUTHENTICATED") {
      // handle authentication failure
      console.log("Authentication failure");
    }
    else if (response.status === "BAD_PARAMS") {
      // handle bad parameters
      console.log("Bad parameters");
    }
  }
  // phone form submission handler
  function phone_btn_onclick() {
    // you can add countryCode and phoneNumber to set values
    AccountKit.login('PHONE', {}, // will use default values if this is not specified
      loginCallback);
  }
  // email form submission handler
  function email_btn_onclick() {
    // you can add emailAddress to set value
    AccountKit.login('EMAIL', {}, loginCallback);
  }
  // destroying session
  function logout() {
        document.location = 'logout.php';
  }
</script>
</html>

file ceklogin.php

<?php
require 'config.php';

session_start();
error_reporting(0);

define( "FB_ACCOUNT_KIT_APP_ID", "YOUR APP ID" );
define( "FB_ACCOUNT_KIT_APP_SECRET", "YOUR APP SECRET" );

$code = $_POST['code'];
$csrf = $_POST['csrf'];

$auth = file_get_contents( 'https://graph.accountkit.com/v1.1/access_token?grant_type=authorization_code&code='.  $code .'&access_token=AA|'. FB_ACCOUNT_KIT_APP_ID .'|'. FB_ACCOUNT_KIT_APP_SECRET );

$access = json_decode( $auth, true );

if( empty( $access ) || !isset( $access['access_token'] ) ){
    return array( "status" => 2, "message" => "Unable to verify the phone number." );
}

//App scret proof key Ref : https://developers.facebook.com/docs/graph-api/securing-requests
$appsecret_proof= hash_hmac( 'sha256', $access['access_token'], FB_ACCOUNT_KIT_APP_SECRET );

//echo 'https://graph.accountkit.com/v1.1/me/?access_token='. $access['access_token'];
$ch = curl_init();

// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, 'https://graph.accountkit.com/v1.1/me/?access_token='. $access['access_token'].'&appsecret_proof='. $appsecret_proof );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_TIMEOUT, '4');
$resp = trim(curl_exec($ch));

curl_close($ch);

$info = json_decode( $resp, true );

if( empty( $info ) || !isset( $info['phone'] ) || isset( $info['error'] ) ){
    return array( "status" => 2, "message" => "Unable to verify the phone number." );
}
else{
$phoneNumber = $info['phone']['national_number'];
//$nohp = str_replace($phoneNumber,'0',0,3);
//echo json_encode( $info );

$rs= $link->query("select * from admin where nohp='$phoneNumber'");
while($row = $link->fetch_array($rs)) {
        $admin_id = $row['admin_id'];
        $username = $row['username'];
        $nama     = $row['nama'];
        $nohp     = $row['nohp'];
    }
    if($link->num_rows > 0)
    {
        setcookie('admin_id',$admin_id,time()+3600);
                setcookie('username',$username,time()+3600);
                //setcookie('password',$password,time()+3600);
                setcookie('nama',$nama,time()+3600);
                setcookie('nohp',$phoneNumber,time()+3600);
                setcookie('token',$csrf,time()+3600);
                header(Location:'index.php');
    }
    else
    {
     echo "gagal";
    }
}
?>

saya sengaja gak cantumin APP ID, APP KEY SECRET disini itu rahasia hehehehe

avatar stefanuspn
@stefanuspn

250 Kontribusi 69 Poin

Dipost 5 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban