//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions {
using System;
using System.Collections.Generic;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Messages;
using DotNetOpenAuth.OpenId.Provider;
using DotNetOpenAuth.OpenId.RelyingParty;
///
/// A sample custom OpenID extension factory.
///
///
/// OpenID extension factories must be registered with the library. This can be
/// done by calling , or by adding a snippet
/// such as the following to your web.config file:
///
/// <dotNetOpenAuth>
/// <openid>
/// <extensionFactories>
/// <add type="DotNetOpenAuth.ApplicationBlock.CustomExtensions.Acme, DotNetOpenAuth.ApplicationBlock" />
/// </extensionFactories>
/// </openid>
/// </dotNetOpenAuth>
///
///
public class Acme : IOpenIdExtensionFactory {
internal const string CustomExtensionTypeUri = "testextension";
internal static readonly Version Version = new Version(1, 0);
public static void Register(OpenIdRelyingParty relyingParty) {
if (relyingParty == null) {
throw new ArgumentNullException("relyingParty");
}
relyingParty.ExtensionFactories.Add(new Acme());
}
public static void Register(OpenIdProvider provider) {
if (provider == null) {
throw new ArgumentNullException("provider");
}
provider.ExtensionFactories.Add(new Acme());
}
#region IOpenIdExtensionFactory Members
///
/// Creates a new instance of some extension based on the received extension parameters.
///
/// The type URI of the extension.
/// The parameters associated specifically with this extension.
/// The OpenID message carrying this extension.
/// A value indicating whether this extension is being received at the OpenID Provider.
///
/// An instance of if the factory recognizes
/// the extension described in the input parameters; null otherwise.
///
///
/// This factory method need only initialize properties in the instantiated extension object
/// that are not bound using .
///
public IOpenIdMessageExtension Create(string typeUri, IDictionary data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole) {
if (typeUri == CustomExtensionTypeUri) {
return isProviderRole ? (IOpenIdMessageExtension)new AcmeRequest() : new AcmeResponse();
}
return null;
}
#endregion
}
}