<?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>jalf.dk &#187; http</title>
	<atom:link href="http://jalf.dk/blog/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://jalf.dk/blog</link>
	<description>Musings and thoughts on programming and other geeky stuff</description>
	<lastBuildDate>Mon, 12 Jul 2010 15:21:00 +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>OpenID 2.0 and HTTP redirects</title>
		<link>http://jalf.dk/blog/2009/12/openid-2-0-and-http-redirects/</link>
		<comments>http://jalf.dk/blog/2009/12/openid-2-0-and-http-redirects/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 23:48:36 +0000</pubDate>
		<dc:creator>jalf</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[openid]]></category>

		<guid isPermaLink="false">http://jalf.dk/blog/?p=417</guid>
		<description><![CDATA[Ever since I signed up on StackOverflow.com roughly a year ago, I’ve had an OpenID. On the whole, I think it’s a great concept, and I wish more sites would allow me to sign in with it. However, a few things have been bothering me about it. When I first signed up, I did a [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I signed up on <a href="http://stackoverflow.com/">StackOverflow.com</a> roughly a year ago, I’ve had an OpenID. On the whole, I think it’s a great concept, and I wish more sites would allow me to sign in with it.</p>

<p>However, a few things have been bothering me about it.<span id="more-417"></span></p>

<p>When I first signed up, I did a bit of research, and found out that you can use your own domain as your OpenID. You simply enter the following in a <code>&lt;head&gt;</code> of a HTML page you control:</p>

<pre><code>&lt;link rel="openid.server" href="http://myopenidprovider" /&gt;
&lt;link rel="openid.delegate" href="http://myopenid-at-that-provider/" /&gt;
</code></pre>

<p>And the URI of that HTML page can now be used as your OpenID. It will forward authentication requests to the specified provider. This gave me a nice clean URI to use as my OpenID, and as a bonus, it meant that I could change my OpenID provider and keep my ID, just by editing this HTML.</p>

<p>Of course, I quickly found out there was a downside as well. When I created this blog, I placed it in <code>http://jalf.dk/blog</code>. I figured I could easily add a redirect from <code>http://jalf.dk</code> and so it wouldn’t matter in the long run.</p>

<p>When I tried adding this redirect, I realized that this of course would also redirect any OpenID requests. My OpenID provider would then see a login attempt from <code>http://jalf.dk/blog</code> instead, and all hell would break loose.</p>

<p>So I removed the redirect, and instead placed this message in <code>http://jalf.dk/</code> along with the OpenID <code>&lt;link&gt;</code> tags:</p>

<blockquote>
  <p>Please go <a href="http://jalf.dk/blog/">here</a> for my blog. Sorry for the lack of a proper redirect.</p>
</blockquote>

<p>Not very elegant, but it worked. OpenID requests were handled correctly, and readers of my blog could follow the link, or just bookmark <code>/blog</code> in the first place.</p>

<p>Today, a friend asked me why I didn’t have a redirect, and I explained the above problem. I didn’t think about it any further until half an hour ago, when I realized that Facebook can be tied to an OpenID account. As I said before, the more services I can log in to with my OpenID, the better, so I attempted to add my OpenID… And got a nasty error message telling me that my OpenID only supported version 1.1, and Facebook required 2.0.</p>

<p>Geez, I hadn’t even realized there were multiple versions.</p>

<p>So I went hunting for a solution. And it turned out to be pretty simple, and have the nice side effect of solving the redirection problem as well!</p>

<p>It turns out that the <code>&lt;link&gt;</code> tags embedded in HTML only work for OpenID 1.0 and 1.1. For 2.0, you have to provide a YADIS XML file.</p>

<p>Unfortunately, there seems to be very few examples online of what this file should <em>look like</em>.
I did find a nice example of using a YADIS file for OpenID 1.0 <a href="http://blog.paulisageek.com/2009/06/easy-openid-delegation-with-yadis.html">here</a>, which got me started. The Wikipedia article on <a href="http://en.wikipedia.org/wiki/Yadis">YADIS</a> held another example, but again only with OpenID 1.0. However, it also shows how to specify LID 2.0, so while I have no clue what LID is for, at least it gave a hint of how to support multiple versions.</p>

<p>Finally, diving into the <a href="http://openid.net/specs/openid-authentication-2_0.html">specification for OpenID 2.0</a>, I discovered the correct URI to specify as <code>&lt;Type&gt;</code> in the YADIS file: <code>http://specs.openid.net/auth/2.0</code>. Of course they just <em>had</em> to change the URI format between versions 1.1 and 2.0. Nothing is ever that easy.</p>

<p>But with this, the last piece fell into place. I created an <code>openid.xml</code> file looking like this:</p>

<pre><code>< ?xml version="1.0" encoding="UTF-8"?>
&lt;xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)"
xmlns:openid="http://openid.net/xmlns/1.0"&gt;
  &lt;XRD&gt;
    &lt;Service priority="50"&gt;
      &lt;Type&gt;http://specs.openid.net/auth/2.0/signon&lt;/Type&gt;
      &lt;URI&gt;http://myopenidprovider&lt;/URI&gt;
      &lt;openid:Delegate&gt;http://myopenid-at-that-provider/&lt;/openid:Delegate&gt;
    &lt;/Service&gt;
    &lt;Service priority="20"&gt;
      &lt;Type&gt;http://openid.net/signon/1.1&lt;/Type&gt;
      &lt;URI&gt;http://myopenidprovider&lt;/URI&gt;
      &lt;openid:Delegate&gt;http://myopenid-at-that-provider/&lt;/openid:Delegate&gt;
    &lt;/Service&gt;
    &lt;Service priority="10"&gt;
      &lt;Type&gt;http://openid.net/signon/1.0&lt;/Type&gt;
      &lt;URI&gt;http://myopenidprovider&lt;/URI&gt;
      &lt;openid:Delegate&gt;http://myopenid-at-that-provider/&lt;/openid:Delegate&gt;
    &lt;/Service&gt;
  &lt;/XRD&gt;
&lt;/xrds:XRDS&gt;
</code></pre>

<p>and using the PHP snippet from <a href="http://blog.paulisageek.com/2009/06/easy-openid-delegation-with-yadis.html">paulisageek</a>,</p>

<pre><code>< ?php
if (strpos($_SERVER['HTTP_ACCEPT'], "application/xrds+xml") !== FALSE) {
  header("Content-Type: application/xrds+xml");
  echo file_get_contents("openid.xml");
}
else {
  header("Location: http://jalf.dk/blog");
}
?>
</code></pre>

<p>I now have:</p>

<ul>
<li>The same nice, short, easy-to-remember OpenID URI I always had</li>
<li>My blog accessible form <code>http://jalf.dk</code></li>
<li>My Facebook account linked to my OpenID</li>
<li>Support for OpenID version 2.0</li>
</ul>

<p>All in all, I’m happy. And now that I’ve documented the process, perhaps the next person who runs into this problem may be a bit happier too.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalf.dk/blog/2009/12/openid-2-0-and-http-redirects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
