Keyvan Nayyeri

God breathing through me

OpenID Delegate Plug-In for Graffiti

OpenID Yes, yet another Graffiti plug-in to add an extra feature to this powerful CMS! This time I’m going to share a very simple plug-in that enables OpenID delegation for Graffiti users.

As you may know, you’re able to use a mechanism in OpenID called delegation in which you use your own URL or domain name as your OpenID but behind the scenes you save yourself from implementing an OpenID provider and use a third party provider. This process is pretty simple and all you need is using a short piece of HTML code in your page header. Recently Jeff Atwood published a post about this cool feature on Stack Overflow blog and you can also find additional details on OpenID specification.

I’m using my own domain name (http://nayyeri.net) as my OpenID URI and to do this I had to add the code to my Graffiti blog; therefore, I implemented a simple plug-in that gets the appropriate values and adds the code to the HTML header.

Here is the implementation of this plug-in that should be self-explanatory.

using System;

using System.Collections.Specialized;

using System.Text;

using System.Web;

using Graffiti.Core;

 

namespace OpenIdDelegation

{

    public class OpenId : GraffitiEvent

    {

        #region Fields

 

        public string SERVER;

        public string DELEGATE;

 

        #endregion

 

        #region EditableForm members

 

        public override string Name

        {

            get

            {

                return "OpenID Delegate";

            }

        }

 

        public override string Description

        {

            get

            {

                return "OpenID delegate plug-in for Graffiti " +

                    "by <a href=\"http://nayyeri.net\">Keyvan Nayyeri</a>.";

            }

        }

 

        public override bool IsEditable

        {

            get

            {

                return true;

            }

        }

 

        protected override NameValueCollection DataAsNameValueCollection()

        {

            NameValueCollection nvc = base.DataAsNameValueCollection();

 

            nvc["SERVER"] = SERVER;

            nvc["DELEGATE"] = DELEGATE;

 

            return nvc;

        }

 

        public override StatusType SetValues(HttpContext context, NameValueCollection nvc)

        {

            base.SetValues(context, nvc);

 

            SERVER = nvc["SERVER"];

            DELEGATE = nvc["DELEGATE"];

 

            return StatusType.Success;

        }

 

        protected override FormElementCollection AddFormElements()

        {

            FormElementCollection fec = new FormElementCollection();

 

            fec.Add(new TextFormElement("SERVER", "Server",

                "Your OpenID server (i.e. https://secure.mp/s/keyvan.mp/server)."));

            fec.Add(new TextFormElement("DELEGATE", "Delegate",

                "Your OpenID delegate (i.e. http://keyvan.mp)."));

 

            return fec;

        }

 

        #endregion

 

        #region GraffitiEvent members

 

        public override void Init(GraffitiApplication ga)

        {

            ga.RenderHtmlHeader += new RenderContentEventHandler(ga_RenderHtmlHeader);

        }

 

        void ga_RenderHtmlHeader(StringBuilder sb, EventArgs e)

        {

            const string pattern = "<link rel=\"{0}\" href=\"{1}\">";

            sb.AppendFormat(pattern, "openid.server", SERVER);

            sb.Append(Environment.NewLine);

            sb.AppendFormat(pattern, "openid.delegate", DELEGATE);

        }

 

        #endregion

    }

}

This code relies on RenderHtmlHeader event and adds the appropriate lines of HTML <link /> elements to the header by applying the passed StringBuilder parameter to it.

Having this plug-in installed, I can configure its settings in control panel with my values.

Configure the plug-in

As a side-note, I’m using my short http://keyvan.mp domain name as my original OpenID provider which belongs to Chi.mp service and requires user invitation. Beside acting as an OpenID provider, this service offers a centralized place for your social networking or bookmarking services plus your contact information. By the way, I have to thank Mahdi for the invitation!

As you can guess, this plug-in will be a part of the next version of Graffiti Extras project, but you can download it as a separate package with source code from here.

3 Comments

Mahdi Taghizadeh
Feb 01, 2009 3:42 PM
#

@Keyvan

Thank you for you nice and useful post (like ever!). And about the invitation, it was just a small gift for a great friend :-)


Keyvan Nayyeri
Feb 01, 2009 3:46 PM
#

@Mahdi

Thank you :-)

Pingback from Dew Drop - February 1, 2009 | Alvin Ashcraft's Morning Dew

Leave a Comment





Ads Powered by Lake Quincy Media Network