Welcome Guest, Not a member yet? Register   Sign In
How to integrate OAuth with CI?
#1

[eluser]Rubiz'[/eluser]
Hello all!

How to integrate this OAuth files with CI?
#2

[eluser]Teks[/eluser]
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.
#3

[eluser]Rubiz'[/eluser]
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??
#4

[eluser].giorgio[/eluser]
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:
Code:
<?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;
Code:
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):
Code:
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:
Code:
...
$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:
Code:
$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);
#5

[eluser]alexman[/eluser]
[quote author=".giorgio" date="1287181990"]I'm currently developing a twitter app, i'll share my full functional model and oauth implementation as soon as it's finished.[/quote]

Hi Griogio,

How's that module coming along?

Cheers,
Alex
#6

[eluser]alexman[/eluser]
Since this is the top thread in google:
Here's a link to Alex Bilbie's OAuth lib for CI:
https://github.com/alexbilbie/CodeIgnite...2.0-Server
#7

[eluser]geotravel[/eluser]
[quote author="alexman" date="1306595062"]Since this is the top thread in google:
Here's a link to Alex Bilbie's OAuth lib for CI:
https://github.com/alexbilbie/CodeIgnite...2.0-Server[/quote]

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
#8

[eluser]n0xie[/eluser]
You could take a look at our OAUTH wrapper
#9

[eluser]bedanand[/eluser]
If you want to integrate oauth authentication system on your website, this one oauth spark library is very promising. It supports both version 1 and version 2 .

Here is the complete tutorial with CI controller and views.

Tutorial on how to use oauth spark library




Theme © iAndrew 2016 - Forum software by © MyBB