1
//-----------------------------------------------------------------------
2 // <copyright file="OpenIdExtensionFactory.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.OpenId
.Extensions
{
8 using System
.Collections
.Generic
;
9 using DotNetOpenAuth
.Messaging
;
10 using DotNetOpenAuth
.OpenId
.ChannelElements
;
11 using DotNetOpenAuth
.OpenId
.Extensions
.AttributeExchange
;
12 using DotNetOpenAuth
.OpenId
.Extensions
.ProviderAuthenticationPolicy
;
13 using DotNetOpenAuth
.OpenId
.Extensions
.SimpleRegistration
;
14 using DotNetOpenAuth
.OpenId
.Messages
;
17 /// An OpenID extension factory that supports registration so that third-party
18 /// extensions can add themselves to this library's supported extension list.
20 internal class OpenIdExtensionFactory
: IOpenIdExtensionFactory
{
22 /// A collection of the registered OpenID extensions.
24 private List
<CreateDelegate
> registeredExtensions
= new List
<CreateDelegate
>();
27 /// Initializes a new instance of the <see cref="OpenIdExtensionFactory"/> class.
29 internal OpenIdExtensionFactory() {
30 this.RegisterExtension(ClaimsRequest
.Factory
);
31 this.RegisterExtension(ClaimsResponse
.Factory
);
32 this.RegisterExtension(FetchRequest
.Factory
);
33 this.RegisterExtension(FetchResponse
.Factory
);
34 this.RegisterExtension(StoreRequest
.Factory
);
35 this.RegisterExtension(StoreResponse
.Factory
);
36 this.RegisterExtension(PolicyRequest
.Factory
);
37 this.RegisterExtension(PolicyResponse
.Factory
);
41 /// A delegate that individual extensions may register with this factory.
43 /// <param name="typeUri">The type URI of the extension.</param>
44 /// <param name="data">The parameters associated specifically with this extension.</param>
45 /// <param name="baseMessage">The OpenID message carrying this extension.</param>
47 /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
48 /// the extension described in the input parameters; <c>null</c> otherwise.
50 internal delegate IOpenIdMessageExtension
CreateDelegate(string typeUri
, IDictionary
<string, string> data
, IProtocolMessageWithExtensions baseMessage
);
52 #region IOpenIdExtensionFactory Members
55 /// Creates a new instance of some extension based on the received extension parameters.
57 /// <param name="typeUri">The type URI of the extension.</param>
58 /// <param name="data">The parameters associated specifically with this extension.</param>
59 /// <param name="baseMessage">The OpenID message carrying this extension.</param>
61 /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
62 /// the extension described in the input parameters; <c>null</c> otherwise.
65 /// This factory method need only initialize properties in the instantiated extension object
66 /// that are not bound using <see cref="MessagePartAttribute"/>.
68 public IOpenIdMessageExtension
Create(string typeUri
, IDictionary
<string, string> data
, IProtocolMessageWithExtensions baseMessage
) {
69 foreach (var factoryMethod
in this.registeredExtensions
) {
70 IOpenIdMessageExtension result
= factoryMethod(typeUri
, data
, baseMessage
);
82 /// Registers a new extension delegate.
84 /// <param name="creator">The factory method that can create the extension.</param>
85 internal void RegisterExtension(CreateDelegate creator
) {
86 this.registeredExtensions
.Add(creator
);