Implementing WebFinger

Working with the WebFinger protocol is actually very easy. You simply make a series of cURL requests to a provider that implements WebFinger, which subsequently returns all of the information we need, as shown in Figure 10-4.

How WebFinger works

Figure 10-4. How WebFinger works

When a web application or service makes a request to a web source that uses WebFinger in order to obtain user information from that site, the web source will return either user record details or error information in the event that no user data was located.

As an example, let’s take a look at extracting profile information using Google’s WebFinger implementation. First, we will make a request to the /.well-known/host-meta file on Google to obtain more data about how Google’s WebFinger implementation works to extract profile information based on users’ email addresses. From a command prompt, we enter the following:

curl http://gmail.com/.well-known/host-meta

Note

When implementing this procedure in a product or service, you can use the PHP cURL library (http://php.net/manual/en/book.curl.php) or PycURL for Python (http://pycurl.sourceforge.net/).

The response that is returned will contain data about the URI template format that Google uses to obtain the user’s profile from her email address:

<?xml version='1.0' encoding='UTF-8'?>
<!-- NOTE: this host-meta end-point is a pre-alpha work in progress.
     Don't rely on it. -->
<!-- Please follow the list at http://groups.google.com/group/webfinger -->
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
     xmlns:hm='http://host-meta.net/xrd/1.0'>
  <hm:Host xmlns='http://host-meta.net/xrd/1.0'>gmail.com</hm:Host>
  <Link rel='lrdd'
        template='http://www.google.com/s2/webfinger/?q={uri}'>
    <Title>Resource Descriptor</Title>
  </Link>
</XRD>

From the preceding response object, we can see that the URI format Google uses is http://www.google.com/s2/webfinger/?q={uri}. Now, if we make another request to Google using that URI, substituting the uri parameter with our email address, we should be able to get a user’s profile data.

We make the following request from the command line:

curl http://www.google.com/s2/webfinger/[email protected]

When we run this, we’ll get the profile response from Google that will deliver the user’s public profile data:

<?xml version='1.0'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
    <Subject>acct:[email protected]</Subject>
    <Alias>http://www.google.com/profiles/nakedtechnologist</Alias>
    <Link rel='http://portablecontacts.net/spec/1.0'
          href='http://www-opensocial.googleusercontent.com/api/people/'/>
    <Link rel='http://portablecontacts.net/spec/1.0#me'
          href='http://www-opensocial.googleusercontent.com/api/
                people/118167121283215553793/'/>
    <Link rel='http://webfinger.net/rel/profile-page'
          href='http://www.google.com/profiles/nakedtechnologist'
          type='text/html'/>
    <Link rel='http://microformats.org/profile/hcard'
          href='http://www.google.com/profiles/nakedtechnologist'
          type='text/html'/>
    <Link rel='http://gmpg.org/xfn/11'
          href='http://www.google.com/profiles/nakedtechnologist'
          type='text/html'/>
    <Link rel='http://specs.openid.net/auth/2.0/provider'
          href='http://www.google.com/profiles/nakedtechnologist'/>
    <Link rel='describedby'
          href='http://www.google.com/profiles/nakedtechnologist'
          type='text/html'/>
    <Link rel='describedby'
          href='http://www.google.com/s2/webfinger/?
                q=nakedtechnologist%40gmail.com&amp;fmt=foaf'
          type='application/rdf+xml'/>
    <Link rel='http://schemas.google.com/g/2010#updates-from'
          href='https://www.googleapis.com/buzz/v1/activities/
                118167121283215553793/@public' type='application/atom+xml'/>
</XRD>

From the return object, we can extract some data about the user:

We can continue this process for any users that may have a public profile.

We can use this same approach to access similar data from other implementers of the WebFinger protocol. For instance, to access data from Yahoo!, we would make cURL requests to the following URIs:

This process is standard among implementers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.88.54