title: facebook data deletion callback implementation in laravel using socialite
body: <p>I am implementing facebook data deletion callback but I got really lost and i can't continue on the <code>JSON</code> response that facebook is expecting.</p>
  <ul>
  <li>Return a JSON response that contains a URL where the user can check the status of their deletion request and an alphanumeric confirmation code. The JSON response has the following form:</li>
  </ul>
  <p><code>{ url: '&lt;url&gt;', confirmation_code: '&lt;code&gt;' }</code></p>
  <p>that is the part that I got lost and stuck. My question is</p>
  <ol>
  <li>what is the URL should do or show.</li>
  <li>what is the logic between the confirmation code</li>
  </ol>
  <p>so far here is what I did on my controller.</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers\User\Auth\Socialite;
  
  use App\Models\User;
  use Illuminate\Http\Request;
  
  class FacebookSocialLoginController extends SocialLoginFactory
  {
  
      public function provider(): string
      {
          return 'facebook';
      }
  
      public function dataDeletionCallback(Request $request)
      {
          $signed_request = $request-&gt;get('signed_request');
          $data = $this-&gt;parse_signed_request($signed_request);
          $user_id = $data['user_id'];
  
          // here will delete the user base on the user_id from facebook
          User::where([
              ['provider' =&gt; 'facebook'],
              ['provider_id' =&gt; $user_id]
          ])-&gt;forceDelete();
  
          // here will check if the user is deleted
          $isDeleted = User::withTrashed()-&gt;where([
              ['provider' =&gt; 'facebook'],
              ['provider_id' =&gt; $user_id]
          ])-&gt;find();
  
          if ($isDeleted ===null) {
              return response()-&gt;json([
                  'url' =&gt; '', // &lt;------ i dont know what to put on this or what should it do
                  'code' =&gt; '', // &lt;------ i dont know what is the logic of this code
              ]);
          }
  
          return response()-&gt;json([
              'message' =&gt; 'operation not successful'
          ], 500);
      }
  
      private function parse_signed_request($signed_request) {
          list($encoded_sig, $payload) = explode('.', $signed_request, 2);
  
          $secret = config('service.facebook.client_secret'); // Use your app secret here
  
          // decode the data
          $sig = $this-&gt;base64_url_decode($encoded_sig);
          $data = json_decode($this-&gt;base64_url_decode($payload), true);
  
          // confirm the signature
          $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
          if ($sig !== $expected_sig) {
              error_log('Bad Signed JSON signature!');
              return null;
          }
  
          return $data;
      }
  
      private function base64_url_decode($input) {
          return base64_decode(strtr($input, '-_', '+/'));
      }
  }
  
  </code></pre>