tag:www.rhnh.net,2008:/yadisYadis - Xavier Shay's Blog2008-04-13T11:02:02ZEnkiXavier Shaynotreal@rhnh.nettag:www.rhnh.net,2008:Post/7562008-04-13T10:54:00Z2008-04-13T11:02:02ZNginx, OpenID delegation and YADIS<p>Typically OpenID delegation reads delegation information out of <span class="caps">HTML</span> headers on your home page:</p><table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="ta"><link</span> <span class="an">rel</span>=<span class="s"><span class="dl">"</span><span class="k">openid.server</span><span class="dl">"</span></span> <span class="an">ref</span>=<span class="s"><span class="dl">"</span><span class="k">http://server.myid.net/server</span><span class="dl">"</span></span> <span class="ta">/></span><tt>
</tt><span class="ta"><link</span> <span class="an">rel</span>=<span class="s"><span class="dl">"</span><span class="k">openid.delegate</span><span class="dl">"</span></span> <span class="an">href</span>=<span class="s"><span class="dl">"</span><span class="k">http://xaviershay.myid.net/</span><span class="dl">"</span></span> <span class="ta">/></span><tt>
</tt></pre></td>
</tr></table>
<p>The problem with this is that any client trying to discover this information needs to fetch your entire home page. If that client is your page (commenting on your own entry, for instance), that request can get queued up behind the same mongrel that was serving the original request, which of course now won’t complete until the OpenID delegation request times out.</p>
<p>There is another way to provide delegation information. Clients will request your home page with an accept header of <code>application/xrds+xml</code> – and you can use that information to serve up a static <a href="http://yadis.org/wiki/Main_Page"><span class="caps">YADIS</span></a> file rather than your home page. Mine looks like this:</p><table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)"<tt>
</tt> xmlns:openid="http://openid.net/xmlns/1.0"><tt>
</tt> <XRD><tt>
</tt><tt>
</tt> <Service priority="1"><tt>
</tt> <Type>http://openid.net/signon/1.0</Type><tt>
</tt> <URI>https://server.myid.net/server</URI><tt>
</tt> <openid:Delegate>https://xaviershay.myid.net/</openid:Delegate><tt>
</tt> </Service><tt>
</tt><tt>
</tt> </XRD><tt>
</tt></xrds:XRDS><tt>
</tt></pre></td>
</tr></table>
<p>And I serve it up with this Nginx rewrite rule:</p><table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">if ($http_accept ~* application/xrds\+xml) {<tt>
</tt> rewrite (.*) $1/yadis.xrdf break;<tt>
</tt>}<tt>
</tt></pre></td>
</tr></table>
<p>Try it in the comfort of your own home:</p><table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">curl -H 'Accept: application/xrds+xml' http://rhnh.net<tt>
</tt></pre></td>
</tr></table>
<p>Ref: <a href="http://www.intertwingly.net/blog/2007/01/03/OpenID-for-non-SuperUsers">OpenID for non-SuperUsers</a></p>