• Stars
    star
    352
  • Rank 120,622 (Top 3 %)
  • Language
    PHP
  • Created about 13 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NO LONGER ACTIVELY MAINTAINED. USE https://github.com/thephpleague/oauth2-client INSTEAD

Codeigniter OAuth 2.0

!!! DEPRECATED !!!

This package is no longer actively maintained. If somebody sends in a pull request with some major security bug then I'll merge it, but otherwise nothing will be done. Use thephpleague/oauth2-client instead.

Authorize users with your application in a driver-base fashion meaning one implementation works for multiple OAuth 2 providers. This is only to authenticate onto OAuth2 providers and not to build an OAuth2 service.

Note that this Spark ONLY provides the authorization mechanism. There's an example controller below, however in a later version there will be a full controller.

Examples

OAuth 2 is split into two sections, clients and providers. A client is an application - perhaps a basic Twitter feed aggregator - which authenticates with an OAuth 2 provider, which in this example would be Twitter itself. You can interact with any provider which is supported in the list below:

  • Facebook
  • Foursquare
  • GitHub
  • Google
  • PayPal
  • Instagram
  • Soundcloud
  • Windows Live
  • YouTube

TODO

  • Requests should be done through a more stable system, there however isn't a Request class in CodeIgniter.
  • Add unit tests and get on Travis

Usage Example

This example will need the user to go to a certain URL, which will support multiple providers. I like to set a controller to handle it and either have one single "session" method - or have another method for callbacks if you want to separate out the code even more.

Here you'll see we have the provider passed in as a URI segment of "facebook" which can be used to find config in a database, or in a config multi-dimensional array. If you want to hard code it all then that is just fine too.

Send your user to http://example.com/auth/session/facebook where Auth is the name of the controller. This will also be the address of the "Callback URL" which will be required by many OAuth 2 providers such as Facebook.

class Auth extends CI_Controller
{
	public function session($provider)
	{
		$this->load->helper('url_helper');
		
		$this->load->spark('oauth2/0.3.1');
	
		$provider = $this->oauth2->provider($provider, array(
			'id' => 'your-client-id',
			'secret' => 'your-client-secret',
		));

		if ( ! $this->input->get('code'))
		{
			// By sending no options it'll come back here
			$provider->authorize();
		}
		else
		{
			// Howzit?
			try
			{
				$token = $provider->access($_GET['code']);
			
				$user = $provider->get_user_info($token);
			
				// Here you should use this information to A) look for a user B) help a new user sign up with existing data.
				// If you store it all in a cookie and redirect to a registration page this is crazy-simple.
				echo "<pre>Tokens: ";
				var_dump($token);
				
				echo "\n\nUser Info: ";
				var_dump($user);
			}
		
			catch (OAuth2_Exception $e)
			{
				show_error('That didnt work: '.$e);
			}
		
		}
	}
}

If all goes well you should see a dump of user data and have $token available. If all does not go well you'll likely have a bunch of errors on your screen.

Contribute

  1. Check for open issues or open a new issue for a feature request or a bug
  2. Fork the repository on Github to start making your changes to the develop branch (or branch off of it)
  3. Write a test which shows that the bug was fixed or that the feature works as expected
  4. Send a pull request and bug me until I merge it

More Repositories

1

awesome-earth

"What can I do about the climate crisis?" Here are 326 things you can do.
JavaScript
1,330
star
2

codeigniter-restclient

STOP USING THIS USE GUZZLE INSTEAD >.<
PHP
686
star
3

dbad

Dont Be a Dick Public License
HTML
529
star
4

codeigniter-template

Template library for CodeIgniter which supports modules, themes, partial views, etc.
HTML
411
star
5

codeigniter-curl

THIS IS NO LONGER MAINTAINED, USE http://docs.guzzlephp.org INSTEAD
PHP
377
star
6

fuel-ninjauth

LONG DEAD EXPERIMENT
PHP
136
star
7

phptherightway-book

The official eBook version of phptherightway.com. Download in PDF/mobi/epub formats from LeanPub.
PHP
126
star
8

codeigniter-cli

Work with CodeIgniter over the command line with handy prompts, clear screen, etc.
PHP
97
star
9

codeigniter-oauth

NO LONGER ACTIVELY MAINTAINED. USE https://github.com/thephpleague/oauth1-client INSTEAD
PHP
84
star
10

codeigniter-unzip

Extract ZIP files in CodeIgniter without installing any PECL extensions for PHP.
PHP
78
star
11

ee2-rest

Integrate RESTful API's into your ExpressionEngine 2.0 website with this Rest module.
PHP
34
star
12

coffeescript-beautifier

Format your coffeescript to make it more beautiful
29
star
13

codeigniter-dwoo

A simple Dwoo template engine implementation for CodeIgniter via Parser library.
PHP
27
star
14

nonblockingbro

Debunking an article suggesting that NodeJS was magically faster than PHP at scraping HTML and traversing the DOM, but used blocking code for one and non-blocking for another.
PHP
25
star
15

livecoding-apisyouwonthate

HTML
24
star
16

codeigniter-prowl

Send iPhone notificiations from your CodeIgniter application with Prowl.
PHP
23
star
17

ee2-widgets

Widgets is a ExpressionEngine 2.1 module that allows even your least experienced client or to manage chunks of intelligent content on there site without needing to learn loads of tags, HTML or call you in to help.
PHP
18
star
18

codeigniter-encoding

A simple library for interacting with the Encoding.com service, allowing you to que audio and video files which they will take, convert and put onto a FTP server.
PHP
17
star
19

tech-talks

Talks for conferences, meetups, corporate gigs, whatever.
HTML
14
star
20

php-ps

PHP Portable Shell
14
star
21

fuelphp-gettingstarted

Code samples for "Getting Started with FuelPHP: Part 2"
PHP
12
star
22

phparse

Parse phpinfo() HTML with PHP
PHP
11
star
23

phil.tech

Computers, humans, the overlap, and remote work.
10
star
24

codeigniter-maxcdn

PHP
9
star
25

book-full-bike-bike-nomad

A book about blowing everything up and starting again over two plus years of being a bike nomad. 34 countries, nowhere to call home, working full time as a software engineer, trying to keep my electronics dry/powered/not stolen, and my carbon footprint super low.
6
star
26

go-workshop

Go
5
star
27

mojo-variables

Set variables in your layout file or anywhere throughout Mojo Regions then use them again anywhere.
PHP
5
star
28

remotefloatsmyboat.com

Collection of reasons why people love working remote, which started before COVID but has only become more true now with the mental wellbeing crisis.
Smarty
4
star
29

openapi-playground

HTML
3
star
30

spectral-demo-circleci

2
star
31

photo-unfucker

Take disorganized files and move them into a nested date directory structure
Ruby
2
star
32

openapi-schema-to-json-schema

2
star
33

mojo-inputs

Get access to GET, POST and Cookie data. Also gives you the users ip address and user agent.
PHP
2
star
34

psr0-naming-oddity

This highlights an oddity in PSR-0 which will cause errors if you instantiate classes inconsistently
PHP
2
star
35

api-design-workshop

2
star
36

go-workshop-php

PHP
2
star
37

covidclimate.com

As the world focuses on tackling COVID-19, we must not forget: this won’t be the last pandemic we suffer.
Smarty
2
star
38

projects

Direct funding for biodiverstiy and carbon sequestration projects for Protect Earth and anyone else who wants to use this open-source software.
2
star
39

tutorial-api-docs-first

API Blueprint
1
star
40

examples-examples

1
star
41

phil.bike

The two-wheeled adventures of Crash MyCiderface
1
star
42

laravel-zuplo-demo

Taking a laravel application and protecting it with the Zuplo API Gateway.
PHP
1
star