//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Extensions {
using System.Collections.Generic;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions.OAuth;
using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.Extensions.UI;
using DotNetOpenAuth.OpenId.Messages;
///
/// An OpenID extension factory that supports registration so that third-party
/// extensions can add themselves to this library's supported extension list.
///
internal class StandardOpenIdExtensionFactory : IOpenIdExtensionFactory {
///
/// A collection of the registered OpenID extensions.
///
private List registeredExtensions = new List();
///
/// Initializes a new instance of the class.
///
internal StandardOpenIdExtensionFactory() {
this.RegisterExtension(ClaimsRequest.Factory);
this.RegisterExtension(ClaimsResponse.Factory);
this.RegisterExtension(FetchRequest.Factory);
this.RegisterExtension(FetchResponse.Factory);
this.RegisterExtension(StoreRequest.Factory);
this.RegisterExtension(StoreResponse.Factory);
this.RegisterExtension(PolicyRequest.Factory);
this.RegisterExtension(PolicyResponse.Factory);
this.RegisterExtension(AuthorizationRequest.Factory);
this.RegisterExtension(AuthorizationApprovedResponse.Factory);
this.RegisterExtension(AuthorizationDeclinedResponse.Factory);
this.RegisterExtension(UIRequest.Factory);
}
///
/// A delegate that individual extensions may register with this factory.
///
/// 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.
///
internal delegate IOpenIdMessageExtension CreateDelegate(string typeUri, IDictionary data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole);
#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) {
foreach (var factoryMethod in this.registeredExtensions) {
IOpenIdMessageExtension result = factoryMethod(typeUri, data, baseMessage, isProviderRole);
if (result != null) {
return result;
}
}
return null;
}
#endregion
///
/// Registers a new extension delegate.
///
/// The factory method that can create the extension.
internal void RegisterExtension(CreateDelegate creator) {
this.registeredExtensions.Add(creator);
}
}
}