Not wanting to follow FB's convoluted example i modified my OAuth Wrap client, and it posted below..
DEMO
http://sandbox.knarly.com/oauth/oauth2.phpCODE
<?php
/**
* This script makes a connection to a oauth server at Facebook
*
* @author Andrew Dodson
* @since June 2010
* @company Knarly Ltd (knarly.com)
*/
$oauths=array(
'facebook' => array(
'path' => "https://graph.facebook.com/oauth/access_token",
'login' => 'https://graph.facebook.com/oauth/authorize',
'key' => '359288236870',
'secret'=> 'put-you-secret-here',
'datamine' => 'https://graph.facebook.com/me?'
),
);
if( ( $srv = @$oauths[@$_GET['service']] ) ){
// if this is the first time the user has connected
if(empty($_GET['code'])){
redirect( $srv['login'], (array(
'client_id' => $srv['key'],
'redirect_uri' => "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
)));
}
else if(!empty($_GET['code'])){
// else check that the wrap_verification_code came from the server we're interrogating
// Can't use http_build_query because that encodes '|' which appears in the wrap_verification_code
try{
$resp = _get( $srv['path'] , array(
'client_id' => $srv['key'],
'client_secret' => $srv['secret'],
'redirect_uri' => urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?service='.$_GET['service']),
'code' => urldecode($_GET['code']),
));
// Datamine
// Return the default contents
$_GET += $resp;
r("RESPONSE", $resp);
}catch(Exception $e){
r("Failed to load", $e);
}
}
/**
* Check it works!
*/
if(!empty($_REQUEST['access_token'])){
$user = file_get_contents( $srv['datamine'] .'access_token=' . $_REQUEST['access_token'] );
r( json_decode($user) );
}
}
// Print to screen a bit of info
function r(){
print "<pre>".print_r(func_get_args(),true)."</pre>";
}
// This redirect the user... in production this would not be a link but a header('Location: '.$path);
function redirect($u,$p){
print "<a href='$u?". http_build_query($p) . "'>Login at $u</a> | ";
}
// GUI
// PRINT ALL THE OAUTH SERVICES TO THE SCREEN
foreach($oauths as $k => $o){
print ' | <a href="'.$_SERVER['SCRIPT_NAME'].'?service='.$k.'">'.$k.'</a>';
}
function implode_with_key($a){
$r=array();
foreach($a as $k=>$o)
$r[] = $k.'='.$o;
return implode('&',$r);
}
function _get($path, $opts){
$resp = file_get_contents( $path . '?' . implode_with_key($opts) );
parse_str($resp , $resp );
return $resp ;
}
?>
Comments
Awesome
Nice
Created 09/06/10
LrqGVQiienzNCZE
I feel so much happier now I undesrnatd all this. Thanks!
Created 07/08/11
QcMweomFgXtglNoAoqP
SFKc16 cpxlqhbjzswm
Created 08/08/11
JeajDDladxgCzlMgOP
zsezdb , [url=http://kxehyharaddg.com/]kxehyharaddg[/url], [link=http://oynlrthpbaar.com/]oynlrthpbaar[/link], http://ukyzabgqgzmv.com/
Created 09/08/11
QcsZKmGeIPiNMt
6T5x9A heshxemcwamn
Created 10/08/11
ziYjFnmOgNfNgeFhvNI
ls0oBd , [url=http://rvlkiopqkuue.com/]rvlkiopqkuue[/url], [link=http://fjqiihxpzjra.com/]fjqiihxpzjra[/link], http://opydqjrzazsx.com/
Created 16/08/11
