title: Codeigniter Authentication library with Facebook support
body: <p>I am building an application that will require users to login via Facebook OR their own email address. I have always in the past used the IonAuth2 library but I cannot quite see how to integrate this with Facebook using the documentation.</p>
  
  <p>Can anyone provide any advice on this matter, would I be better of using another Codeigniter library or does anyone know of how to integrate Facebook into IonAuth2 easily.</p>
  
  <p>I have already got the basics working with Facebook in terms of setting up an application and using the API to login via your Facebook as illustrated below - I am just trying to think of the best way of doing this in relation to the authentication system (ideally ionAuth2 if possible)</p>
  
  <pre><code>    public function index()
      {
        $user = $this-&gt;facebook-&gt;getUser();
  
        if($user) {
          try {
              $user_info = $this-&gt;facebook-&gt;api('/me');
              echo '&lt;pre&gt;'.htmlspecialchars(print_r($user_info, true)).'&lt;/pre&gt;';
              echo 'user found';
              // save this info..
              $this-&gt;load-&gt;model('fb_users_model');
              $this-&gt;fb_users_model-&gt;insert_user($user_info); // id, first_name, last_name, link, username, gender, email, timezone, locale, verified, updated_time
  
              echo 'we have logged in..got to some page..';
              echo "&lt;a href=/logout&gt;Logout&lt;/a&gt;";
          } catch(FacebookApiException $e) {
              echo '&lt;pre&gt;'.htmlspecialchars(print_r($e, true)).'&lt;/pre&gt;';
              $user = null;
          }
      } else {
          echo "&lt;a href=\"{$this-&gt;facebook-&gt;getLoginUrl()}\"&gt;Login using Facebook&lt;/a&gt;";
      }
  }
  </code></pre>