<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cakebaker &#187; oauth</title>
	<atom:link href="http://cakebaker.42dh.com/tags/oauth/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:23:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using OAuth-enabled APIs with CakePHP</title>
		<link>http://cakebaker.42dh.com/2008/09/01/using-oauth-enabled-apis-with-cakephp/</link>
		<comments>http://cakebaker.42dh.com/2008/09/01/using-oauth-enabled-apis-with-cakephp/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 14:44:32 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[oauth]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=769</guid>
		<description><![CDATA[A growing number of APIs support OAuth, i.e. it is possible to give service A access to service B without giving B&#8217;s username/password to A. In this article I&#8217;m going to show you how to use OAuth-enabled APIs with CakePHP (and the OAuth consumer component I have written). First, there are some preparations necessary, namely [...]]]></description>
			<content:encoded><![CDATA[<p>A growing number of APIs support <a href="http://oauth.net">OAuth</a>, i.e. it is possible to give service A access to service B without giving B&#8217;s username/password to A. In this article I&#8217;m going to show you how to use OAuth-enabled APIs with CakePHP (and the OAuth consumer component I have written).</p>
<p>First, there are some preparations necessary, namely the download of the required files:</p>
<ul>
<li>Get the <a href="http://cakebaker.42dh.com/downloads/oauth-component-for-cakephp/">OAuth component</a> and place its content in &#8220;app/controllers/components&#8221;</li>
<li>Get the <a href="http://oauth.googlecode.com/svn/code/php/OAuth.php">OAuth library</a> and put it in &#8220;vendors/OAuth&#8221;</li>
<li>Set the security level in app/config/core.php to &#8220;low&#8221; (thanks to <a href="http://www.intertwinesys.com/">Bryan Young</a> for mentioning in the comments)</li>
</ul>
<p>The next step is to register your application at the service provider (e.g. <a href="http://fireeagle.yahoo.net/developer">Yahoo&#8217;s Fire Eagle</a>) to get consumer key and consumer secret. Those values are then stored in a class called FireEagleConsumer if we go on using Fire Eagle as example service provider in this article:</p>
<pre>
<code>// app/controllers/components/oauth_consumers/fire_eagle_consumer.php
class FireEagleConsumer extends AbstractConsumer {
    public function __construct() {
        parent::__construct('THE KEY', 'THE SECRET');
    }
}</code>
</pre>
<p>This class is then used by the component to access consumer key and secret.</p>
<p>Using an OAuth-enabled API consists of four steps:</p>
<ul>
<li>Get RequestToken</li>
<li>Authorize RequestToken</li>
<li>Exchange RequestToken for AccessToken</li>
<li>Access the API using the AccessToken</li>
</ul>
<p>In the ideal case the first three steps are performed once. But it is also possible that for example the service provider expires the AccessToken after some time, and so those steps have to be repeated.</p>
<p>Anyway, let&#8217;s have a look at how those steps look in code. We start with getting the RequestToken:</p>
<pre>
<code>// app/controller/oauth_consumer_example_controller.php
class OauthConsumerExampleController extends AppController {
    public $uses = array();
    public $components = array('OauthConsumer');
	
    public function index() {
        $requestToken = $this-&gt;OauthConsumer-&gt;getRequestToken('FireEagle', 'https://fireeagle.yahooapis.com/oauth/request_token');
        $this-&gt;Session-&gt;write('requestToken', $requestToken);
    }
}</code>
</pre>
<p>The code is probably self-explanatory, we have to add the component to the $components array, and then we get the RequestToken from the specified url (while writing this I just realized it would make sense to move the url to the FireEagleConsumer class&#8230;).</p>
<p>The next step is simple: we have to redirect the user to the authorize page of the service provider:</p>
<pre>
<code>// app/controller/oauth_consumer_example_controller.php
class OauthConsumerExampleController extends AppController {
    public $uses = array();
    public $components = array('OauthConsumer');
	
    public function index() {
        $requestToken = $this-&gt;OauthConsumer-&gt;getRequestToken('FireEagle', 'https://fireeagle.yahooapis.com/oauth/request_token');
        $this-&gt;Session-&gt;write('requestToken', $requestToken);
        $this-&gt;redirect('http://fireeagle.yahoo.net/oauth/authorize?oauth_token='.$requestToken-&gt;key);
    }
}</code>
</pre>
<p>After the RequestToken is authorized, we get redirected to a callback url we specified while registering the application. We can now exchange the authorized RequestToken for an AccessToken:</p>
<pre>
<code>// app/controller/oauth_consumer_example_controller.php
class OauthConsumerExampleController extends AppController {
    public $uses = array();
    public $components = array('OauthConsumer');

    ...

    public function callback() {
        $requestToken = $this-&gt;Session-&gt;read('requestToken');
        $accessToken = $this-&gt;OauthConsumer-&gt;getAccessToken('FireEagle', 'https://fireeagle.yahooapis.com/oauth/access_token', $requestToken);
    }
}</code>
</pre>
<p>In a real use case you would also save the data of the AccessToken (key and secret) to the database, so you don&#8217;t have to perform all those steps every time you want to call the API. </p>
<p>The last step is to call the API, in this example to get the latest location of the user:</p>
<pre>
<code>// app/controller/oauth_consumer_example_controller.php
class OauthConsumerExampleController extends AppController {
    public $uses = array();
    public $components = array('OauthConsumer');

    ...

    public function callback() {
        $requestToken = $this-&gt;Session-&gt;read('requestToken');
        $accessToken = $this-&gt;OauthConsumer-&gt;getAccessToken('FireEagle', 'https://fireeagle.yahooapis.com/oauth/access_token', $requestToken);
        $data = $this-&gt;OauthConsumer-&gt;get('FireEagle', $accessToken-&gt;key, $accessToken-&gt;secret, 'https://fireeagle.yahooapis.com/api/0.1/user');
        // do something with the data
    }
}</code>
</pre>
<p>That&#8217;s it. Feedback is welcome!</p>
<p>Update 2008-09-15: Slightly adapted for new version of the component.<br />
Update 2009-01-14: Adding hint about security level.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/09/01/using-oauth-enabled-apis-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>OpenID versus OAuth from the user&#8217;s perspective</title>
		<link>http://cakebaker.42dh.com/2008/04/01/openid-versus-oauth-from-the-users-perspective/</link>
		<comments>http://cakebaker.42dh.com/2008/04/01/openid-versus-oauth-from-the-users-perspective/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 15:25:47 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[oauth]]></category>
		<category><![CDATA[openid]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=592</guid>
		<description><![CDATA[In this article I want to show the differences between OpenID and its younger cousin OAuth by providing for each a typical user scenario. First the scenario for OpenID: User wants to access his account on example.com example.com (the &#8220;Relying Party&#8221; in OpenID lingo) asks the user for his OpenID User enters his OpenID example.com [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I want to show the differences between <a href="http://openid.net">OpenID</a> and its younger cousin <a href="http://oauth.net">OAuth</a> by providing for each a typical user scenario.</p>
<p>First the scenario for OpenID:</p>
<ul>
<li>User wants to access his account on example.com</li>
<li>example.com (the &#8220;Relying Party&#8221; in OpenID lingo) asks the user for his OpenID</li>
<li>User enters his OpenID</li>
<li>example.com redirects the user to his OpenID provider</li>
<li>User authenticates himself to the OpenID provider</li>
<li>OpenID provider redirects the user back to example.com</li>
<li>example.com allows the user to access his account</li>
</ul>
<p>And now the scenario for OAuth:</p>
<ul>
<li>User is on example.com and wants to import his contacts from mycontacts.com</li>
<li>example.com (the &#8220;Consumer&#8221; in OAuth lingo) redirects the user to mycontacts.com (the &#8220;Service Provider&#8221;)</li>
<li>User authenticates himself to mycontacts.com (which can happen by using OpenID)</li>
<li>mycontacts.com asks the user whether he wants to authorize example.com to access his contacts</li>
<li>User makes his choice</li>
<li>mycontacts.com redirects the user back to example.com</li>
<li>example.com retrieves the contacts from mycontacts.com</li>
<li>example.com informs the user that the import was successful</li>
</ul>
<p>From those scenarios we can see that OpenID is about <a href="http://en.wikipedia.org/wiki/Authentication">authentication</a> (i.e. I can identify myself with an url) whereas OAuth is about <a href="http://en.wikipedia.org/wiki/Authorization">authorization</a> (i.e. I can grant permission to access my data on some website to another website, without providing this website the authentication information for the original website).</p>
<p>I hope this helps to keep apart those two standards :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/04/01/openid-versus-oauth-from-the-users-perspective/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
