ExtremeSwank OpenID
OpenIdClient Class
NamespacesExtremeSwank.OpenIdOpenIdClient
Provides an OpenID Relying Party (Consumer) compatible with OpenID 1.1 and 2.0 specifications.
Declaration Syntax
C#Visual BasicVisual C++
[SerializableAttribute]
public sealed class OpenIdClient : ClientCore
<SerializableAttribute> _
Public NotInheritable Class OpenIdClient _
	Inherits ClientCore
[SerializableAttribute]
public ref class OpenIdClient sealed : public ClientCore
Members
All MembersConstructorsMethodsPropertiesEvents



IconMemberDescription
OpenIdClient()()()
Provides a new OpenIdClient object with default settings.

OpenIdClient(NameValueCollection)
Provides a new OpenIdClient object using a custom set of request arguments.

CreateRequest()()()
Creates the redirect URL for the OpenID authentication request, and, if in an ASP.NET context, will automatically redirects the user's web browser to the OpenID Provider.

CreateRequest(Boolean, Boolean)
Creates the redirect URL for the OpenID authentication request.
(Overrides ClientCore.CreateRequest(Boolean, Boolean).)
DetectAndHandleResponse()()()
Look at the current request arguments and perform work appropriately, invoking events as conditions occur.
(Inherited from ClientCore.)
EnableStatefulMode(IAssociationPersistence, ISessionPersistence)
Enable Stateful authentication mode using supplied association and session persistence plug-ins.
(Inherited from ClientCore.)
Equals(Object) (Inherited from Object.)
ErrorState
Returns the current error state
(Inherited from ClientCore.)
Finalize()()() (Inherited from Object.)
GetHashCode()()() (Inherited from Object.)
GetType()()() (Inherited from Object.)
Identity
Gets or sets the OpenID idenitifer and normalizes the value

Init()()()
Shared initialization method - should be used by constructor.
(Inherited from ClientCore.)
IsValidIdentity()()()
Independently performs discovery on the supplied OpenID and determines whether or not it is valid.

LastDiscoveryResult
Last DiscoveryResult object created during discovery, or populated manually.
(Inherited from ClientCore.)
MemberwiseClone()()() (Inherited from Object.)
ProviderUrl
Gets or sets the URL of Identity Provider
(Inherited from ClientCore.)
ReceivedCancel
A user-initiated Cancel response has been received from an OpenID Provider.
(Inherited from ClientCore.)
ReceivedResponse
A response has been received from an OpenID Provider.
(Inherited from ClientCore.)
ReceivedSetupNeeded
Immediate mode request has failed, should issue a standard authentication request.
(Inherited from ClientCore.)
RequestedMode
Checks the current page request and returns the requested mode.
(Inherited from ClientCore.)
RetrieveUser()()()
After successful validation, provides an object to hold the user information
(Inherited from ClientCore.)
ReturnUrl
Gets or sets a URL to transfer user upon approval - defaults to current page
(Inherited from ClientCore.)
StateContainer
Gets the current StateContainer object in use by this OpenIdClient.
(Inherited from ClientCore.)
ToString()()() (Inherited from Object.)
TrustRoot
Gets or sets the URL that will serve as the base root of trust - defaults to current domain
(Inherited from ClientCore.)
UseDirectedIdentity
Set to true to enforce use of Directed Identity.

ValidateResponse()()()
Validates an OpenID authentication response.
(Overrides ClientCore.ValidateResponse()()().)
ValidationFailed
The authentication response has failed validation.
(Inherited from ClientCore.)
ValidationSucceeded
The authentication response has been validated successfully.
(Inherited from ClientCore.)
Examples
Here is a simple procedural example of using OpenIdClient in an ASP.NET application:
CopyC#
using ExtremeSwank.OpenID;

public partial class _Default
{
   protected void LoginButton_Click(object sender, EventArgs e)
   {
       OpenIdClient openid = new OpenIdClient();
       openid.Identity = LoginBox1.Text;
       openid.CreateRequest();
   }
   protected void LogOutButton_Click(object sender, EventArgs e)
   {
       Session["OpenID_UserObject"] = null;
       // Handle user logout here
   }
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           OpenIdClient openid = new OpenIdClient();
           switch (openid.RequestedMode)
           {
              case RequestedMode.IdResolution:
                   if (openid.ValidateResponse())
                   {
                       OpenIdUser thisuser = openid.RetrieveUser();
                       Session["OpenID_UserObject"] = thisuser;
                       // Authentication successful - Perform login here
                   }
                   else
                   {
                       // Authentication failure handled here
                   }
                   break;
               case RequestedMode.CanceledByUser:
                   // User has cancelled authentication - handle here
                   break;
           }
       }
   }
}
A more advanced method, based on .NET events, is below:
CopyC#
using ExtremeSwank.OpenID;
using ExtremeSwank.OpenID.Plugins.Extensions;

public partial class _Default
{

   protected void Page_Load(object sender, EventArgs e)
   {
       // If this is not a postback, start up the Consumer
       // and handle any OpenID request, if present
       if (!IsPostBack)
       {
           OpenIdClient openid = GetConsumer();
           openid.DetectAndHandleResponse();
       }
   }

   protected OpenIdClient GetConsumer()
   {
       // Initialize the OpenID Consumer
       OpenIdClient openid = new OpenIdClient();

       // Subscribe to all the events that could occur
       openid.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded);
       openid.ValidationFailed += new EventHandler(openid_ValidationFailed);
       openid.ReceivedCancel += new EventHandler(openid_ReceivedCancel);

       return openid;
   }

   protected void Button_Click(object sender, EventArgs e)
   {
       OpenIdClient openid = GetConsumer();

       // Set Identity to the text of a field
       openid.Identity = openid_url.Text;

       openid.CreateRequest();
   }

   protected void openid_ReceivedCancel(object sender, EventArgs e)
   {
       // Request has been cancelled. Respond appropriately.
   }

   protected void openid_ValidationSucceeded(object sender, EventArgs e)
   {
       // User has been validated!  Respond appropriately.
       OpenIdUser UserObject = ((OpenIdClient)sender).RetrieveUser();
   }

   protected void openid_ValidationFailed(object sender, EventArgs e)
   {
       // Validating the user has failed.  Respond appropriately.
   }
}
For non-ASP.NET environments:
CopyC#
IAssociationPersistence associationManager;
ISessionPersistence sessionManager;

public MyObject() 
{
    // Create the association manager.
    // Note that IAssociationPeristence object is only needed if OpenIdClient.EnableStatefulMode()
    // is used.
    string dsnstr = "Driver={SQL Server};Server=SERVER\\INSTANCE;Database=OpenIDDatabase;Uid=sa;Pwd=password;"
    associationManager = new OdbcAssociationManager(dsnstr, "Prefix_");
    // Use the SingularSessionManager for situations where the session does not actually
    // need to be persisted, assuming that this instance will survive the entire OpenID
    // authentication lifecycle.  DbSessionManager can also be used if you want to
    // save session state into a database.
    // Note that ISessionPersistence object is only needed if OpenIdClient.EnableStatefulMode()
    // is used.
    sessionManager = new SingularSessionManager();
}

public OpenIdClient SetupConsumer(NameValueCollection arguments) 
{
    // Create a new OpenIdClient object
    OpenIdClient openid = new OpenIdClient(arguments);

    // Enable Stateful mode.  If Stateful mode is not desired, just omit
    // this step.
    openid.EnableStatefulMode(associationManager, sessionManager);    

    openid.TrustRoot = "http://myserver.com/";
    openid.ReturnUrl = "http://myserver.com/myPage";
    return openid;
}

// Discover the supplied OpenID identity's Provider URL, build and
// return a redirect URL for the web browser.
public string RetrieveAuthenticationUrl(string identity) 
{
    OpenIdClient openid = SetupConsumer(new NameValueCollection());
    openid.Identity = identity;

    // Discover the supplied OpenID and return the redirect URL
    return openid.CreateRequest(false, false);
}

// An authentication response has been received from the OpenID Provider
// by way of the user's web browser.  Process the data in the response.
// If the response is valid, return an OpenIdUser object containing
// the authentication details.
public OpenIdUser ProcessAuthenticationResponse(NameValueCollection arguments) 
{
    OpenIdClient openid = SetupConsumer(arguments);
    switch (openid.RequestedMode) 
    {
        case RequestedMode.IdResolution:
            if (openid.ValidateResponse()) {
                OpenIdUser thisuser = openid.RetrieveUser();
                return thisuser;
            }
            break;
    }
    return null;
}
Inheritance Hierarchy
Object
ClientCore
 OpenIdClient

Assembly: ExtremeSwank.OpenId (Module: ExtremeSwank.OpenId) Version: 4.0.0.1 (4.0.0.1)