<?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>Bubble Foundry &#187; oAuth</title>
	<atom:link href="http://www.bubblefoundry.com/blog/tag/oauth/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bubblefoundry.com</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 18:23:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.bubblefoundry.com/?pushpress=hub'/>
		<item>
		<title>oAuth on App Engine, Part 2</title>
		<link>http://www.bubblefoundry.com/blog/2009/05/oauth-on-app-engine-part-2/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/05/oauth-on-app-engine-part-2/#comments</comments>
		<pubDate>Sun, 24 May 2009 15:45:14 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Analytics]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[Gdata]]></category>
		<category><![CDATA[gdata-python-client]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[oAuth]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=219</guid>
		<description><![CDATA[In my previous post I described how to use Google&#8217;s federated login to get an oAuth access token. Now that we&#8217;ve stored our access token, we&#8217;re going to want to use it in future requests to access the user&#8217;s data. Here&#8217;s how: # set up service gdata_service = gdata.service.GDataService() gdata.alt.appengine.run_on_appengine(gdata_service) gdata_service.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, settings.GOOGLE_CONSUMER_KEY, settings.GOOGLE_CONSUMER_SECRET) # build [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post I described <a href="http://www.bubblefoundry.com/blog/2009/05/openid-and-oauth-on-app-engine/">how to use Google&#8217;s federated login</a> to get an oAuth access token. Now that we&#8217;ve stored our access token, we&#8217;re going to want to use it in future requests to access the user&#8217;s data. Here&#8217;s how:<br />
<code><br />
# set up service<br />
gdata_service = gdata.service.GDataService()<br />
gdata.alt.appengine.run_on_appengine(gdata_service)<br />
gdata_service.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, settings.GOOGLE_CONSUMER_KEY, settings.GOOGLE_CONSUMER_SECRET)<br />
</code><code><br />
# build access_token object and signed request<br />
scopes = [settings.GOOGLE_ANALYTICS_ACCOUNT_URI, settings.GOOGLE_ANALYTICS_DATA_URI]<br />
oauth_input_params = gdata.auth.OAuthInputParams(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, settings.GOOGLE_CONSUMER_KEY, settings.GOOGLE_CONSUMER_SECRET)<br />
access_token = gdata.auth.OAuthToken(scopes=scopes, oauth_input_params=oauth_input_params)<br />
access_token.set_token_string(person.accessToken)<br />
gdata_service.current_token = access_token<br />
</code><code><br />
# request feed<br />
feed = data_service.GetFeed(settings.GOOGLE_ANALYTICS_ACCOUNT_URI)<br />
</code></p>
<p><code>feed</code> is a GDataFeed object which can easily be iterated over, like so:<br />
<code><br />
for entry in feed.entry:<br />
&nbsp;&nbsp;&nbsp;&nbsp;print entry.title.text<br />
</code></p>
<p>To be honest, I&#8217;m not sure if the scopes are necessary but I included them for the sake of completeness. Setting <code>oauth_input_params</code> for the oAuth token is essential and something that took me a while to figure out – I had assumed that setting the parameters for the Gdata service would be enough.</p>
<p>I am directly assigning the access token to the Gdata service. I had originally tried to use the setter – <code>gdata_service.SetOAuthToken(access_token)</code> – but had problems and switched to direct assignment. However, my problem could very well have been somewhere else, so feel free to try using the method.</p>
<p>Finally, you may have noticed that I&#8217;m querying the <a href="http://code.google.com/apis/analytics/docs/gdata/gdataDeveloperGuide.html">Analytics Data API</a>. I hope to have more to announce about that soon. In the meantime, I&#8217;ll note that <code><a href="http://code.google.com/p/gdata-python-client/">gdata-python-client</a></code> doesn&#8217;t have specific Analytics support, which is why I&#8217;m using the generic Gdata service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/05/oauth-on-app-engine-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OpenID and oAuth on App Engine</title>
		<link>http://www.bubblefoundry.com/blog/2009/05/openid-and-oauth-on-app-engine/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/05/openid-and-oauth-on-app-engine/#comments</comments>
		<pubDate>Mon, 11 May 2009 02:27:08 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Gdata]]></category>
		<category><![CDATA[gdata-python-client]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google-app-engine-django-openid]]></category>
		<category><![CDATA[Hybrid]]></category>
		<category><![CDATA[oAuth]]></category>
		<category><![CDATA[Open Stack]]></category>
		<category><![CDATA[OpenID]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=208</guid>
		<description><![CDATA[Building on my previous post, here are some things I learned today while working to get OpenID and oAuth playing nicely with Django on App Engine. While App Engine has a very nice login system that hooks seamlessly into Google Accounts, gaining access to the user&#8217;s data via one of the Gdata feeds requires an [...]]]></description>
			<content:encoded><![CDATA[<p>Building on my <a href="http://www.bubblefoundry.com/blog/2009/05/installing-the-google-app-engine-sdk-and-django-102/">previous post</a>, here are some things I learned today while working to get OpenID and oAuth playing nicely with Django on App Engine.</p>
<p>While App Engine has a very nice login system that hooks seamlessly into Google Accounts, gaining access to the user&#8217;s data via one of the <a href="http://code.google.com/apis/gdata/">Gdata</a> feeds requires an <a href="http://code.google.com/apis/gdata/auth.html">additional authorization</a> (you would use oAuth of course). However, Google has also introduced a <a href="http://code.google.com/apis/accounts/docs/OpenID.html">federated login method</a> whereby you can send the user to one screen where they both login and approve your access via oAuth to their data. So, I gave up development speed in favor of something that is hopefully simpler for my users. If you want to know more, Joseph Smarr of Plaxo has a good writeup of <a href="http://josephsmarr.com/2009/02/03/test-driving-the-new-hybrid/">how the hybrid OpenID + oAuth combination came about</a>.<span id="more-208"></span></p>
<p>After many frustrating attempts trying to get any of the <em>many</em> Django OpenID apps to work, all of which seemed to go haywire when touching App Engine (even if they claimed support), I found the <a href="http://code.google.com/p/google-app-engine-django-openid/">google-app-engine-django-openid</a> app. It&#8217;s quite simplistic – it doesn&#8217;t seem to connect to Django&#8217;s auth system at all – but, most importantly, it worked right out of the box on my App Engine install. Thanks, <a href="http://wtanaka.com/">Wesley</a>! Since I am requiring all users to login via a Google account, I simply skipped the first step in google-app-engine-django-openid&#8217;s login process, having the user enter their OpenID URL, and went to the next step, endpoint discovery. Beyond that all I had to do was add the <a href="http://code.google.com/apis/accounts/docs/OpenID.html#Parameters">additional oAuth parameters</a> to my OpenID request and, on the return, upgrade the signed request token to an access token. <a href="http://code.google.com/p/gdata-python-client/">gdata-python-client</a> provides all the oAuth mechanisms you need as part of its authorization suite.</p>
<p>Of course, getting an access token was easier said than done, due the gdata library&#8217;s oAuth module being designed with the normal oAuth authorization flow in mind. To start using it much later in the oAuth process required me to initialize a bunch of things I wouldn&#8217;t have otherwise needed to handle. In the interest in saving people time, here&#8217;s the final code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">signed_request_token = gdata.<span style="color: black;">auth</span>.<span style="color: black;">OAuthToken</span><span style="color: black;">&#40;</span>key=args<span style="color: black;">&#91;</span><span style="color: #483d8b;">'openid.ext2.request_token'</span><span style="color: black;">&#93;</span>, secret=<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
gdata_service = gdata.<span style="color: black;">service</span>.<span style="color: black;">GDataService</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
gdata.<span style="color: black;">alt</span>.<span style="color: black;">appengine</span>.<span style="color: black;">run_on_appengine</span><span style="color: black;">&#40;</span>gdata_service<span style="color: black;">&#41;</span>
gdata_service.<span style="color: black;">SetOAuthInputParameters</span><span style="color: black;">&#40;</span>gdata.<span style="color: black;">auth</span>.<span style="color: black;">OAuthSignatureMethod</span>.<span style="color: black;">HMAC_SHA1</span>, settings.<span style="color: black;">GOOGLE_CONSUMER_KEY</span>, settings.<span style="color: black;">GOOGLE_CONSUMER_SECRET</span><span style="color: black;">&#41;</span>
access_token = gdata_service.<span style="color: black;">UpgradeToOAuthAccessToken</span><span style="color: black;">&#40;</span>signed_request_token<span style="color: black;">&#41;</span>
person.<span style="color: black;">accessToken</span> = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>access_token<span style="color: black;">&#41;</span></pre></div></div>

<p>It&#8217;s not a lot of code, really, but it took a <em>lot</em> of poking through the gdata code to figure it all out! Note that the access token returned by <code>UpgradeToOAuthAccessToken()</code> is not a string but can easily be converted to and from a string for storage.</p>
<p>When using parts of the <a href="http://code.google.com/p/gdata-python-client/">gdata-python-client</a> library, always make sure to <a href="http://googledataapis.blogspot.com/2008/04/release-hounds-support-for-app-engine.html">set the http transport</a> to App Engine&#8217;s urllib: <code>gdata.service.http_request_handler = gdata.urlfetch</code>. In general, if you&#8217;re getting any sort of weird error from something that uses a network connection, it&#8217;s probably because you&#8217;re not using Google&#8217;s <a href="http://code.google.com/appengine/docs/python/urlfetch/">URL fetch service</a>.</p>
<p>In additional, one key thing I learned is that, while you don&#8217;t get a secret back with your signed request token, you <em>must</em> <a href="http://groups.google.com/group/google-federated-login-api/web/oauth-support-in-googles-federated-login-api">pass along an empty string</a> for the secret when calling <code>gdata.service.GDataService.UpgradeToOAuthAccessToken</code>. <code>None</code> or <code>False</code> will cause errors in gdata&#8217;s oAuth library.</p>
<p>Finally, testing. Because Google requires your realm to match your domain for the oAuth request, I couldn&#8217;t test the authentication and authorization process on my local machine running the App Engine SDK behind a router. Instead, I just keep pushed changes to my live install on App Engine. I&#8217;m sure there&#8217;s a better solution, most likely running the SDK on a machine with a public address and getting an oAuth consumer key from Google tied to that address. Also, I didn&#8217;t use it but the <a href="http://googlecodesamples.com/oauth_playground/">oAuth Playground</a> looks like a good place to test your oAuth interaction with Gdata services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/05/openid-and-oauth-on-app-engine/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

