Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/dgeorgiev/facebook-ion-auth
- Owner: dgeorgiev
- Created: 2013-03-06T19:56:12.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-09-30T08:27:50.000Z (about 7 years ago)
- Last Synced: 2024-04-28T05:53:56.296Z (6 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 25
- Watchers: 5
- Forks: 24
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codeigniter - facebook-ion-auth - Facebook login working with ion_auth. (Libraries)
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.
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.