Part of the EllisLab Network
   
 
How to integrate OAuth with CI?
Posted: 12 December 2008 10:29 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  221
Joined  12-20-2007

Hello all!

How to integrate this OAuth files with CI?

 Signature 

Rúbia Gardini - Social Media Developer

Profile
 
 
Posted: 13 December 2008 05:37 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  54
Joined  11-22-2008

OAuth-PHP project can be found here:

http://code.google.com/p/oauth-php/

There you will find also some documentation on how to setup an OAuth Consumer and on how to setup an OAuth Service Provider - including samples of the functions you will need to implement to get the OAuth services you need up and running.

The way you will implement OAuth functionality in CodeIgniter depends very much on what you want to use OAuth for - but you would usually implement the OAuth functions as part of the model or controller classes.

Profile
 
 
Posted: 16 December 2008 12:21 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  221
Joined  12-20-2007

I have loved this link, was the best one I have read.

I imagine that I have to put all library files in CI library? I have some difficulty in understand how to use classes and libraries, CI website could not have a tutorial for this? A step-by-step guide?

About the database: I would have to use only the consumer side tables??

 Signature 

Rúbia Gardini - Social Media Developer

Profile
 
 
Posted: 15 October 2010 01:33 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  3
Joined  10-11-2010

i don’t have a step-by-step guide for you, but it is fairly easy to implement the oauth library for your needs. below a quick overview, hope it helps. After altering the library you can just create a model for each oauth application (ie. a twitter model, facebook model etc.). I’m currently developing a twitter app, i’ll share my full functional model and oauth implementation as soon as it’s finished.

OAuth Implementation Overview:
—-
* Download the oauth-php library from code.google.com (see link above) and extract package
* Create /path/to/ci/install/system/application/libraries/OAuthClient.php and ./OAuth/
* OAuthClient.php is just an empty with require statements:

<?php
require_once(dirname(__FILE__).'/OAuth/OAuthStore.php');
require_once(
dirname(__FILE__).'/OAuth/OAuthRequester.php');
class 
OAuthClient {

* Copy contents of oauth-php/library/ to your newly created OAuth dir in the ci-libraries directory
—————
Now comes the tricky part, pay attention!

OAuth-php uses different methods for storing the tokens/key’s/etc. The class files can be found at /system/application/libraries/OAuth/store/. For this example I’ll use the session method (the easiest one the change), but it is the same for the other store methods.

Ok let’s go! Open up OAuth/store/OAuthStoreSession.php

First add a new private var to store the CI super object;

class OAuthStoreSession extends OAuthStoreAbstract
{
  
private $session;
  private 
$ci;
... 

Next uncomment the if clause starting the session, get a superobject instance en load the session library (if not already loaded):

public function __construct$options = array() )
{
  
/**
  if (!session_id()) {
    session_start();
  }
  */
  
$this->ci =& get_instance();
  
$this->ci->load->library('session');
... 

Now simply change every occurence of fetching or setting a session variable ($_SESSION[’...’]) with the CI code, but pay attention! The $_SESSION variable is passed by reference, so we also need to set the session variable at the end of the constructor:

...
$this->ci->session->set_userdata(
  array(
'oauth_'.$options['consumer_key'=> $this->session)
);
... 

Now also change the file /system/application/libraries/OAuth/session/OAuthSessionSESSION.php and you’re done! Load the oauth library and use as you would normally:

$this->load->library('OAuthClient'); // make available the lib
$options = array();
$oauth_store OAuthStore::instance('Session'$options);
$request = new OAuthRequester($request_uri'GET/POST'$params);
$result doRequest(0); 
Profile
 
 
Posted: 20 May 2011 07:25 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  2
Joined  05-20-2011
.giorgio - 15 October 2010 05:33 PM

I’m currently developing a twitter app, i’ll share my full functional model and oauth implementation as soon as it’s finished.

Hi Griogio,

How’s that module coming along?

Cheers,
Alex

Profile
 
 
Posted: 28 May 2011 06:04 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  2
Joined  05-20-2011

Since this is the top thread in google:
Here’s a link to Alex Bilbie’s OAuth lib for CI:
https://github.com/alexbilbie/CodeIgniter-OAuth-2.0-Server

Profile
 
 
Posted: 09 June 2011 04:22 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  3
Joined  05-18-2011
alexman - 28 May 2011 10:04 AM

Since this is the top thread in google:
Here’s a link to Alex Bilbie’s OAuth lib for CI:
https://github.com/alexbilbie/CodeIgniter-OAuth-2.0-Server

Anybody have try use this? It is ready to use as OAUTH provider with https://github.com/philsturgeon/codeigniter-restserver ??? I have add this to API REST Server (PHILSTURGEON) by I don’t know how to check oauth is working with my API REST. I would like use OAUTH with get access PUT/POST on API

Profile
 
 
Posted: 09 June 2011 07:40 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1438
Joined  03-10-2009

You could take a look at our OAUTH wrapper

 Signature 

Isset | Isset Public Code Repo | Simple Message Library | Session Profiler for CI2.0 | CI session issues in IE

Profile