IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

http://opauth.org/

GITHUB:

https://github.com/opauth/opauth/

Quickstart

Guide on how to run the bundled example:

  • Set DocumentRoot of your web server to example/. Example està al codi font disponible a github (Opauth can be instantiated in your own PHP app, but we will leave that out of this quick start guide)
  • Configure Opauth: First, make a copy of opauth config's file by copying or renaming opauth.conf.php.default to opauth.conf.php.
  • Open up opauth.conf.php and make the necessary changes.
  • Install some Opauth strategies. Place the strategy files in lib/Opauth/Strategy/.
Exemple facebook:
Download the strategy files and place them at lib/Opauth/Strategy/Facebook/.
  • Follow the steps at Opauth-Facebook's README to set up your Faceobok app.
  • Add the following at opauth.conf.php under Strategy as such:
<?php
'Strategy' => array(
    // Define strategies here. 

    'Facebook' => array(
        'app_id' => 'YOUR APP ID',
        'app_secret' => 'YOUR APP SECRET'
    ),
);

Estrategies

Google

Aneu a:

https://code.google.com/apis/console/

i autentiqueu-vos. Feu click a

Create Project

Aneu a APIS and Auth > Credential i a Oauth seleccioneu:

Create new client ID

Exemple facebook

Pas a pas per provar la llibreria:

Aneu a la web:

$ cd /usr/share/
$ sudo git clone https://github.com/opauth/opauth/
$ cd opauth

Ara instal·leu almenys una estrategia:

$ cd /usr/share/opauth/lib/Opauth/Strategy
$ sudo git clone https://github.com/opauth/facebook

Configurem Apache:

$ sudo joe /etc/apache2/conf.d/opauth

El fitxer ha de quedar:

Alias /opauthexample /usr/share/opauth

Apliqueu els canvir de Apache:

$ sudo /etc/init.d/apache reload

Abans d'anar a la URL:

http://localhost/opauthexample/facebook

Ara cal configurar opauth i la estrategia:

$ cd /usr/share/opauth/example
$ sudo cp opauth.conf.php.default opauth.conf.php
$ sudo joe /usr/share/opauth/example/opauth.conf.php

Canvieu:

        'path' => '/',

per

        'path' => '/opauthexample/',

I descomenteu les línies de facebook. El fitxer ha de quedar de la següent manera:

$ cat opauth.conf.php
<?php
/**
 * Opauth basic configuration file to quickly get you started
 * ==========================================================
 * To use: rename to opauth.conf.php and tweak as you like
 * If you require advanced configuration options, refer to opauth.conf.php.advanced
 */

$config = array(
/**
 * Path where Opauth is accessed.
 *  - Begins and ends with /
 *  - eg. if Opauth is reached via http://example.org/auth/, path is '/auth/'
 *  - if Opauth is reached via http://auth.example.org/, path is '/'
 */
	'path' => '/opauthexample/',

/**
 * Callback URL: redirected to after authentication, successful or otherwise
 */
	'callback_url' => '{path}callback.php',
	
/**
 * A random string used for signing of $auth response.
 */
	'security_salt' => 'LDFmiilYf8Fyw5W10rx4W1KsVrieQCnpBzzpTBWA5vJidQKDx8pMJbmw28R1C4m',
		
'Strategy' => array(
    'Facebook' => array(
 	   'app_id' => 'APP ID',
    	'app_secret' => 'APP_SECRET'
 	),
 ) 
);

Finalment al no utilitzar /var/www configureu correctament ModRewrite

$ sudo joe /usr/share/opauth/example/.htaccess 
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ /opauthexample/index.php [QSA,L]
</IfModule>

Afegiu una aplicació a facebook per obtenir el APP_ID i el APP_SECRET. Aneu a:

https://developers.facebook.com/apps/

I feu click a Add a new App. Escolliu el tipus aplicació web (WWW). Li podeu posar de nom:

prova_opauth

i feu click a:

Create new facebokk app ID

Diu-li que no és un app de test d'un altre i escolliu qualsevol categoria.

Dieu-li que us voleu salta l'assistent!

IMPORTANT: Cal afegir localhost com a plataforma a l'apartat Settings > Basic > Add Platform - http://stackoverflow.com/questions/4532721/facebook-development-in-localhost/7493806#7493806

Ara poseu les claus

$ sudo joe /usr/share/opauth/example/opauth.conf.php
'Strategy' => array(
   'Facebook' => array(
          'app_id' => '633647244565851',
          'app_secret' => 'a371543342e5bebc2b9fd5547ad381ad5'
       ),
 )
);

Demos

Code igniter

http://www.sitepoint.com/integrating-open-authentication-using-opauth/

Vegeu també