title: The security of the social network authentication using Laravel Socialite
body: <p>I am using the Socialite for a social network authentication in Laravel App. I wanted to add registration using social networks, without possibility to use the classic registration method byentering username and password. Currently, I decided to create a User model which contains name and username, that is used for uathorization and separate tables in db for each social network that contain user_id and id from the social network as PK. </p>
  
  <p>When the system receives the user's id in chosen social network, it checks the appropriate table for that id and if it exists there - get's the user id and authenticates user to the system. If not - adds there and also authenticates. </p>
  
  <p>The function that handles the response from the social network:</p>
  
  <pre><code>public function handleProviderCallback($social)
  {
      $userSocial = Socialite::driver($social)-&gt;user();
  
      $registeredUser = DB::table($social.'_accounts')-&gt;find($userSocial-&gt;id);
  
      if(!empty($registeredUser)) {
          Auth::loginUsingId($registeredUser-&gt;user_id);
      }else{
          $user = new User;
          $user-&gt;name = $userSocial-&gt;name;
          $user-&gt;username = 'user2222'; //will be implementer in future
          $user-&gt;avatar = $userSocial-&gt;avatar;
          $user-&gt;save();
  
          DB::table($social.'_accounts')-&gt;insert(['id' =&gt; $userSocial-&gt;id, 'user_id' =&gt; $user-&gt;id ]);
          Auth::loginUsingId($user-&gt;id);
      }
  
          return redirect()-&gt;action('HomeController@index');
  }
  </code></pre>
  
  <p>The question is about security, may you explain me whether that solution is quite secure or not? I mean the authentication without password, just in case receiving the user's id from the social network. Can that query from the social network be forged to get an access to smb'a account? </p>