<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Anything Geek Related &#187; Python</title>
	<atom:link href="http://debounce.wordpress.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://debounce.wordpress.com</link>
	<description>Anything to do with Dev</description>
	<lastBuildDate>Mon, 26 Jul 2010 01:07:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='debounce.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/475c7a4c8c16c61439ebfd02a6e0e03d?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Anything Geek Related &#187; Python</title>
		<link>http://debounce.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://debounce.wordpress.com/osd.xml" title="Anything Geek Related" />
	<atom:link rel='hub' href='http://debounce.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Python &#8211; 2 legged OAuth Woes</title>
		<link>http://debounce.wordpress.com/2009/11/01/python-2-legged-oauth-woes/</link>
		<comments>http://debounce.wordpress.com/2009/11/01/python-2-legged-oauth-woes/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 11:30:35 +0000</pubDate>
		<dc:creator>debounce</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[2-legged]]></category>
		<category><![CDATA[OAuth]]></category>

		<guid isPermaLink="false">http://debounce.org/?p=56</guid>
		<description><![CDATA[While I have been programming with Python I have found the following intricacies with the OAuth 2-legged approach, in regards to using web based APIs (all the examples are in Python &#38; refer to the Vimeo API). Note I don&#8217;t believe this is well documented, and have at times found the following confusing: When using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debounce.wordpress.com&#038;blog=6162417&#038;post=56&#038;subd=debounce&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While I have been programming with Python I have found the following intricacies with the OAuth 2-legged approach, in regards to using web based APIs (all the examples are in Python &amp; refer to the Vimeo API).</p>
<p>Note I don&#8217;t believe this is well documented, and have at times found the following confusing:</p>
<ol>
<li>When using Web based APIs, one does not need to be concerned about the concept of &#8216;tokens&#8217; if you are using a 2-legged OAuth approach (even though alot of sites proclaim that one should always be requesting for tokens, and even the python OAuth APIs that exist in github.com don&#8217;t really indicate that one does not need tokens). <em><span style="color:#3366ff;">This basically means you do not need a token if you are doing a HTTP &#8216;GET&#8217; request (depending which web based API you are using).</span></em></li>
<li>When using 2-legged OAuth (or 3-legged for that matter), <span style="color:#3366ff;"><em>you must indicate all the parameters that are going to be sent using the HTTP &#8216;GET&#8217; request (equally this should apply for &#8216;POST&#8217; requests as well) before you generate a &#8216;signature method&#8217;.</em></span></li>
<li>As of OAuth Standard 1.0a I believe there is a slightly broken nature in how OAuth is used and believe it is actually a flaw in the OAuth protocol, which I discovered by accident. When using a 2-legged approach (refer to example below), this method will &#8216;intermittently&#8217; work, when I first tested this (using the vimeo API), it actually worked for the 1st iteration, but failed consecutively for 3 iterations before working again and then intermittently after that:</li>
</ol>
<div id="_mcePaste" style="padding-left:30px;">#Using Leah Culver&#8217;s Python library @ http://github.com/leah/python-oauth</div>
<div style="padding-left:30px;">#Note I have deliberately left out my API key and secret for the purposes of this blog post</div>
<div style="padding-left:30px;">VIMEO_API_URL = &#8216;http://vimeo.com/oauth/v2&#8242;</div>
<div style="padding-left:30px;">consumer = oauth.OAuthConsumer(VIMEO_API_KEY, VIMEO_API_SEC)</div>
<div id="_mcePaste" style="padding-left:30px;">oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url=VIMEO_API_URL)</div>
<div style="padding-left:30px;">oauth_request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1() , consumer, None)</div>
<div style="padding-left:30px;">#After I sign the request then I form the other parameters with the corresponding values:</div>
<div style="padding-left:30px;">http_request = &#8217;http://vimeo.com/api/rest/v2?&#8217; + &#8216;apiMethod&#8217; + &#8216;param_value&#8217; + str(oauth_request.to_postdata())</div>
<p>I originally thought it was a bug on the web API provider&#8217;s end, but it turned out to be a bug on how I perform the OAuth signing request. Basically, the <em>bug was that I was signing the request before setting/applying the web API methods/parameter values I wanted </em>(which obviously changed the hash of the signing request method). However, I believe that because it does not require a token, you can &#8216;brute force&#8217; it to intermittently work if you call it enough times (possibly because the hash code for the request signature matches once in a while).</p>
<p>However, with a bit of help from using the php example provided by vimeo for their OAuth API, I figured out that one had to encode the parameters before signing the request:</p>
<p style="padding-left:30px;">consumer = oauth.OAuthConsumer(VIMEO_API_KEY, VIMEO_API_SEC)</p>
<p style="padding-left:30px;">oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url=VIMEO_API_URL)</p>
<p style="padding-left:30px;"><strong>oauth_request.set_parameter(&#8216;format&#8217;, &#8216;json&#8217;)</strong></p>
<p style="padding-left:30px;"><strong>oauth_request.set_parameter(&#8216;method&#8217;, &#8216;vimeo.videos.getByTag&#8217;)</strong></p>
<p style="padding-left:30px;"><strong>oauth_request.set_parameter(&#8216;tag&#8217;, tagname)</strong></p>
<p style="padding-left:30px;">oauth_request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1() , consumer, None)</p>
<p style="padding-left:30px;">http_request = &#8216;http://vimeo.com/api/v2?&#8217; + str(oauth_request.to_postdata())</p>
<p>Note: you could manually identify each OAuth required parameter without using the method: &#8216;from_consumer_and_token()&#8217; but I found it easier to use it to save some code space (though I think the name is somewhat counterintuitive) as a non-token http url needs to be specified and is used for 2-legged OAuth.</p>
<div>Hope this helps anyone else who is trying to figure out how to use 2-legged OAuth (whether using Python or not) and is using examples from the web or from examples in an OAuth library, though I believe all examples I found only covered 3-legged approach, which requires an actual token request! I don&#8217;t believe a wrapper needs to be written for the 2-legged approach but there needs to be better examples to help facilitate developers understanding the 2-legged approach.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debounce.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debounce.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debounce.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debounce.wordpress.com&#038;blog=6162417&#038;post=56&#038;subd=debounce&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debounce.wordpress.com/2009/11/01/python-2-legged-oauth-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/069913f0f676e5cc5427b9f91c85e45e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">debounce</media:title>
		</media:content>
	</item>
	</channel>
</rss>
