Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dgeorgiev/facebook-ion-auth

facebook login working with ion_auth (codeigniter)
https://github.com/dgeorgiev/facebook-ion-auth

Last synced: 3 days ago
JSON representation

facebook login working with ion_auth (codeigniter)

Awesome Lists containing this project

README

        

facebook-ion-auth
=================

Facebook login working with [CodeIgniter Ion Auth](http://benedmunds.com/ion_auth/)

## Requirement

- [CodeIgniter Ion Auth](http://benedmunds.com/ion_auth/)

## Installation

- Copy `config/facebook_ion_auth.php` to `application/config/facebook_ion_auth.php`.
- Copy `libraries/Facebook_ion_auth.php` to `application/libraries/Facebook_ion_auth.php`.
- Configure your Facebook API settings in `application/config/facebook_ion_auth.php` for
- `app_id` - Your app id
- `app_scret` - Your app secret key
- `scope` - custom permissions check - http://developers.facebook.com/docs/reference/login/#permissions
- `fields` - fields to retrieve from Facebook; if set to `''`, default is `id,first_name,last_name`; See https://developers.facebook.com/docs/graph-api/reference/user
- `redirect_uri` - url to redirect back from facebook. If set to `''`, `site_url('')` will be used

## Example Usage

Assuming that you have installed [CodeIgniter Ion Auth](http://benedmunds.com/ion_auth/), add this in `application/config/autoload.php`.

$autoload['libraries'] = array('ion_auth', 'Facebook_ion_auth');

Create `application/core/MY_AuthController.php` and put this code into the file

load->config('ion_auth', true);

if (uri_string() != 'auth/login') {
$this->_is_login();
}
}

private function _is_login()
{
if (!$this->ion_auth->logged_in()) {
redirect('auth/login');
}
}
}

To auto-load all files in `application/core/`, add this code in `application/config/config.php`.

/**
| -------------------------------------------------------------------
| Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0) {
require(APPPATH . 'core/'. $class . '.php');
}
}

Extends the default controller `application/controllers/Welcome.php` to `MY_AuthController.php` for authentication check.

class Welcome extends MY_AuthController {
// ....
}

Create a new controller file `application/controllers/Facebook_login.php` with the following code:

facebook_ion_auth->login();
}

/**
* Controller that is redirected back from facebook after login
*/
public function action()
{
$code = $this->input->get('code');
if ($code) {
$this->facebook_ion_auth->login();
redirect('/');
} else {
redirect('auth/login');
}
}
}

In `application/views/auth/login.php`, add "Login with Facebook" button using the Facebook_login controller created above.

Login with Facebook

Update `application/config/facebook_ion_auth.php` for `redirect_uri`.

$config['redirect_uri'] = site_url('facebook_login/action'); // url to redirect back from facebook.

Then, when you access your application in the browser, you will see the login form with facebook login button.