I like to use the WordPress native methods when I can, here's my take on oAuth. The examples below retrieves the access token
<br />
<?php<br />
define('FACEBOOK_APPID','123'); // replace 123 with your app id<br />
define('FACEBOOK_APPSECRET','abc'); // replace abc with your app secret<br />
define('REDIRECTURI','https://your.redirect.url');</p>
<p>if ($_GET['code'] != '') {<br />
if ($_GET['state'] != '' && wp_verify_nonce($_GET['state'], 'my-nonce')) {</p>
<p> $api_url = sprintf("https://graph.facebook.com/oauth/access_token?client_id=%s&redirect_uri=%s&client_secret=%s&code=%s",<br />
urlencode(FACEBOOK_APPID),<br />
urlencode(REDIRECTURI),<br />
urlencode(FACEBOOK_APPSECRET),<br />
urlencode($_GET['code'])<br />
);</p>
<p> $response = wp_remote_request($api_url, array(<br />
'timeout' => 60,<br />
'sslverify' => false,<br />
'method' => 'GET'<br />
));</p>
<p> if( is_wp_error( $response ) ) {<br />
echo 'ERROR';<br />
} else {<br />
$args = wp_parse_args( wp_remote_retrieve_body($response), array() );<br />
echo $args['access_token'];<br />
}<br />
}<br />
} else {<br />
$facebook_dialog_url = sprintf("https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s&state=%s",<br />
FACEBOOK_APPID,<br />
urlencode(REDIRECTURI),<br />
wp_create_nonce ('my-nonce')<br />
);</p>
<p> echo '<a href="'. $facebook_dialog_url .'">LOGIN TO FACEBOOK</a> <br />';<br />
}<br />
?><br />
<br />
<?php<br />
define('GIST_CLIENTID','123'); // replace 123 with your client id<br />
define('GIST_CLIENTSECRET','abc'); // replace abc with your client secret<br />
define('REDIRECTURI','https://your.redirect.url');</p>
<p>if ($_GET['code'] != '') {<br />
$response = wp_remote_request('https://github.com/login/oauth/access_token', array(<br />
'method' => 'POST',<br />
'timeout' => 60,<br />
'sslverify' => false,<br />
'body' => array(<br />
'client_id' => GIST_CLIENTID,<br />
'client_secret' => GIST_CLIENTSECRET,<br />
'code' => $_GET['code'],<br />
'redirect_uri' => REDIRECTURI<br />
)<br />
));</p>
<p> if (is_wp_error( $response )) {<br />
echo 'Something went wrong! <br />';<br />
} else {<br />
$args = wp_parse_args( wp_remote_retrieve_body($response), array() );<br />
echo $args['access_token'];<br />
}<br />
} else {<br />
$gist_dialog_url = sprintf("https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s",<br />
GIST_CLIENTID,<br />
urlencode(REDIRECTURI)<br />
);<br />
echo '<a href="'. $gist_dialog_url .'">LOGIN IN TO GIST (GITHUB)</a> <br />';<br />
}<br />
?><br />
.. more will be added when I get time to play with other services and their oAuth implementation.