If you ever used an OpenID from Yahoo!, you probably noticed the following warning shown by Yahoo!:

“Warning: This website has not confirmed its identity with Yahoo! and might
be fraudulent. Do not share any personal information with this website
unless you are certain it is legitimate.”

The reason you get such a warning is that Yahoo! makes use of an optional, but recommended, OpenID 2.0 feature called “Return URL Verification”, and the OpenID relying party (i.e. the application you want to log in) doesn’t provide the necessary data for this feature.

So, to avoid that the users of your application will get this warning when they log in with their OpenIDs, you have to provide a document with the return URLs, and you have to say where this document is located.

Ok, let’s start with the document. It is a Yadis (i.e. XML) document where you have to list all return URLs as services. Return URLs are URLs to which the OpenID provider redirects the user after the authentication process.

If we use an XML layout:

<?php
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo $content_for_layout;
?>

then the Yadis document looks like:

<xrds:XRDS
    xmlns:xrds="xri://$xrds"
    xmlns:openid="http://openid.net/xmlns/1.0"
    xmlns="xri://$xrd*($v*2.0)">
    <XRD>
        <Service priority="0">
            <Type>http://specs.openid.net/auth/2.0/return_to</Type>
            <URI>http://example.com/users/login</URI>
        </Service>
    </XRD>
</xrds:XRDS>

In the corresponding action we have to set the layout and the correct content type:

public function yadis() {
    $this->layout = 'xml';
    header('Content-type: application/xrds+xml');
}

We have now a document describing the return URLs, but it’s of no use if the OpenID provider is not able to find this document.

So we have to provide an X-XRDS-Location header with the URL of the Yadis document. This header must be set at the URL we use as trust root (it is usually the root of the application). In our example we have to set the header in the action we use for rendering the homepage for example.com:

public function index() {
    header('X-XRDS-Location: http://example.com/openid/yadis');
    ...
}

The last step is to test whether the return URL verification works. For this purpose we have to log in with a Yahoo! OpenID. The warning I showed at the beginning of this article should now disappear.

That’s it. I hope it was understandable ;-)